mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-12-14 11:47:33 +00:00
Add visitor_seen
to the log context
This commit is contained in:
parent
166dc6b4fa
commit
1ce92714c4
3 changed files with 17 additions and 7 deletions
14
log/event.go
14
log/event.go
|
@ -3,6 +3,7 @@ package log
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"heckel.io/ntfy/util"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -11,12 +12,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
fieldTag = "tag"
|
fieldTag = "tag"
|
||||||
fieldError = "error"
|
fieldError = "error"
|
||||||
fieldTimeTaken = "time_taken_ms"
|
fieldTimeTaken = "time_taken_ms"
|
||||||
fieldExitCode = "exit_code"
|
fieldExitCode = "exit_code"
|
||||||
tagStdLog = "stdlog"
|
tagStdLog = "stdlog"
|
||||||
timestampFormat = "2006-01-02T15:04:05.999Z07:00"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Event represents a single log event
|
// Event represents a single log event
|
||||||
|
@ -143,7 +143,7 @@ func (e *Event) Render(l Level, message string, v ...any) string {
|
||||||
}
|
}
|
||||||
e.Message = fmt.Sprintf(message, v...)
|
e.Message = fmt.Sprintf(message, v...)
|
||||||
e.Level = l
|
e.Level = l
|
||||||
e.Timestamp = e.time.Format(timestampFormat)
|
e.Timestamp = util.FormatTime(e.time)
|
||||||
if !appliedContexters {
|
if !appliedContexters {
|
||||||
e.applyContexters()
|
e.applyContexters()
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,6 +143,7 @@ func (v *visitor) contextNoLock() log.Context {
|
||||||
fields := log.Context{
|
fields := log.Context{
|
||||||
"visitor_id": visitorID(v.ip, v.user),
|
"visitor_id": visitorID(v.ip, v.user),
|
||||||
"visitor_ip": v.ip.String(),
|
"visitor_ip": v.ip.String(),
|
||||||
|
"visitor_seen": util.FormatTime(v.seen),
|
||||||
"visitor_messages": info.Stats.Messages,
|
"visitor_messages": info.Stats.Messages,
|
||||||
"visitor_messages_limit": info.Limits.MessageLimit,
|
"visitor_messages_limit": info.Limits.MessageLimit,
|
||||||
"visitor_messages_remaining": info.Stats.MessagesRemaining,
|
"visitor_messages_remaining": info.Stats.MessagesRemaining,
|
||||||
|
|
|
@ -14,6 +14,15 @@ var (
|
||||||
durationStrRegex = regexp.MustCompile(`(?i)^(\d+)\s*(d|days?|h|hours?|m|mins?|minutes?|s|secs?|seconds?)$`)
|
durationStrRegex = regexp.MustCompile(`(?i)^(\d+)\s*(d|days?|h|hours?|m|mins?|minutes?|s|secs?|seconds?)$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
timestampFormat = "2006-01-02T15:04:05.999Z07:00" // Like RFC3339, but with milliseconds
|
||||||
|
)
|
||||||
|
|
||||||
|
// FormatTime formats a time.Time in a RFC339-like format that includes milliseconds
|
||||||
|
func FormatTime(t time.Time) string {
|
||||||
|
return t.Format(timestampFormat)
|
||||||
|
}
|
||||||
|
|
||||||
// NextOccurrenceUTC takes a time of day (e.g. 9:00am), and returns the next occurrence
|
// NextOccurrenceUTC takes a time of day (e.g. 9:00am), and returns the next occurrence
|
||||||
// of that time from the current time (in UTC).
|
// of that time from the current time (in UTC).
|
||||||
func NextOccurrenceUTC(timeOfDay, base time.Time) time.Time {
|
func NextOccurrenceUTC(timeOfDay, base time.Time) time.Time {
|
||||||
|
|
Loading…
Reference in a new issue