Documentation
¶
Overview ¶
Logging package for unified JSON logging. Will look like this: {"time": xxx, "level": xxx, "component": xxx, "message": xxx, "key": xxx}
Index ¶
- type Event
- func (ev *Event) Any(key string, val interface{}) *Event
- func (ev *Event) Bool(key string, val bool) *Event
- func (ev *Event) Dur(key string, d time.Duration) *Event
- func (ev *Event) Err(err error) *Event
- func (ev *Event) Fields(fields map[string]interface{}) *Event
- func (ev *Event) Float64(key string, v float64) *Event
- func (ev *Event) Int(key string, val int) *Event
- func (ev *Event) Int64(key string, v int64) *Event
- func (ev *Event) Msg(msg string)
- func (ev *Event) Str(key, val string) *Event
- func (ev *Event) Strs(key string, vals []string) *Event
- func (ev *Event) Time(key string, t time.Time) *Event
- func (ev *Event) Uint64(key string, v uint64) *Event
- type Logger
- func (l *Logger) AttachHook(hook zerolog.Hook) *Logger
- func (l *Logger) AttachPublisher(pub NATSPublisher, service string, maxPerSec int64) *Logger
- func (l *Logger) Debug(msg string)
- func (l *Logger) DebugE() *Event
- func (l *Logger) Error(msg string)
- func (l *Logger) ErrorE() *Event
- func (l *Logger) Fatal(msg string)
- func (l *Logger) Info(msg string)
- func (l *Logger) InfoE() *Event
- func (l *Logger) LogRequest(next http.Handler) http.Handler
- func (l *Logger) Panic(msg string)
- func (l *Logger) SetLevel(level zerolog.Level)
- func (l *Logger) Warn(msg string)
- func (l *Logger) WarnE() *Event
- func (l *Logger) ZeroLogger() zerolog.Logger
- type LoggerConfig
- type NATSHook
- type NATSHookOptions
- type NATSPublisher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event wraps a *zerolog.Event with a small chainable, typed-field API so callers can attach structured fields instead of interpolating them into the message string, e.g. l.WarnE().Str("email", email).Str("clientIP", ip). Msg("login: invalid credentials"). The terminal Msg call emits the log line.
func (*Event) Any ¶
Any adds an arbitrary value under key, reflected into structured fields. Use it for the %v/%+v cases where the value is not an error and has no dedicated typed method above.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func NewLoggerWithHook ¶
NewLoggerWithHook creates a logger with a hook pre-attached.
func (*Logger) AttachHook ¶
AttachHook adds a hook to this Logger in place and returns the same Logger. This mutates the existing Logger so that any code holding a reference (e.g., middleware closures) sees the updated logger with the hook.
func (*Logger) AttachPublisher ¶
func (l *Logger) AttachPublisher(pub NATSPublisher, service string, maxPerSec int64) *Logger
AttachPublisher configures this Logger's capture writer to publish every log event (with its structured fields) to NATS under the given service name, rate-limited to maxPerSec entries per second. It returns the same Logger. This is the structured replacement for AttachHook on the NATS log path: the capture writer is part of the MultiLevelWriter created in NewLogger, so it survives SetLevel and needs no re-attach when the level changes.
func (*Logger) LogRequest ¶
LogRequest is HTTP middleware that emits a structured access log for each request with typed fields (method, uri, status, clientIP, latencyMs, requestID) instead of an interpolated string. It honors an inbound X-Request-Id header and echoes the request id back on the response so it can be correlated across services and in the admin Logs UI.
func (*Logger) ZeroLogger ¶
ZeroLogger returns the underlying zerolog.Logger for packages that need it
type LoggerConfig ¶
type NATSHook ¶
type NATSHook struct {
// contains filtered or unexported fields
}
NATSHook is a zerolog Hook that publishes log events to NATS.
func NewNATSHook ¶
func NewNATSHook(opts *NATSHookOptions) *NATSHook
NewNATSHook creates a new zerolog hook that publishes to NATS.
type NATSHookOptions ¶
type NATSHookOptions struct {
Publisher NATSPublisher
Service string
Component string
MaxPerSec int64 // Max log entries per second (default 100)
}
NATSHookOptions configures the NATS log hook.