Documentation
¶
Index ¶
- func StacktraceReadableOneliner(stacktrace []byte) string
- type Event
- func (e *Event) Array(k string, v *zerolog.Array) IEvent
- func (e *Event) Bytes(k string, bb []byte) IEvent
- func (e *Event) Caller(skip ...int) IEvent
- func (e *Event) Dict(k string, v *zerolog.Event) IEvent
- func (e *Event) Float64(k string, v float64) IEvent
- func (e *Event) ILogger() ILogger
- func (e *Event) IfActive(f func(ev IEvent)) IEvent
- func (e *Event) Inactive() IEvent
- func (e *Event) Int(k string, v int) IEvent
- func (e *Event) Msgtag(msgtag *Msgtag, ss ...string) IEvent
- func (e *Event) RawJSON(k string, rj []byte) IEvent
- func (e *Event) RequestId(s string) IEvent
- func (e *Event) Send()
- func (e *Event) SendMsg(s string)
- func (e *Event) SendMsgf(s string, vv ...any)
- func (e *Event) SendTitle(s string)
- func (e *Event) Str(k, v string) IEvent
- func (e *Event) Strf(k, s string, vv ...any) IEvent
- func (e *Event) Strs(k string, vv []string) IEvent
- func (e *Event) SubSystem(s string) IEvent
- func (e *Event) Time(k string, t time.Time) IEvent
- func (e *Event) Title(s string) IEvent
- type IEvent
- type ILogger
- type Logger
- func (l *Logger) AddUO(uo any) ILogger
- func (l *Logger) DebugEvent() (e IEvent)
- func (l *Logger) ErrEvent(err error) (e IEvent)
- func (l *Logger) ErrorEvent() (e IEvent)
- func (l *Logger) GetNutzLogger() *Logger
- func (l *Logger) GetZeroLoggerPtr() *zerolog.Logger
- func (l *Logger) InfoEvent() (e IEvent)
- func (l *Logger) SetLevel(level zerolog.Level) ILogger
- func (l *Logger) SubLoggerInitChain() IEvent
- func (l *Logger) TraceEvent() (e IEvent)
- func (l *Logger) WarnEvent() (e IEvent)
- type Msgtag
- type Settings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StacktraceReadableOneliner ¶ added in v1.27.0
Make a one-line representation of Go stracktrace, optimized to be human-readable in one-line form. It's useful when reading stacktraces logged into logging systems, where it's represented as a one-liner, with line breaks represented as \n, et al. Typical usage idiom:
e.Str("stacktrace", logger.StacktraceReadableOneliner(debug.Stack()))
Types ¶
type Event ¶
type IEvent ¶
type IEvent interface {
// Inactivation applies to real events only, all data set ops will be bypassed.
// However, if applied to sub-logger init chain, nothing is bypassed.
Inactive() IEvent
// This is useful to do some work only if the event is activated, e.g. do some data prep
// or JSON marshalling, and waste no time otherwise.
//
// logger.InfoEvent().Inactive().Msgtag().IfActive(func(ev IEvent) {
// // do some heavy work, then
// ev.RawJSON(b)
// }).Title("my event").Send()
IfActive(func(IEvent)) IEvent
Caller(skip ...int) IEvent
Str(string, string) IEvent
Strf(string, string, ...any) IEvent
Strs(string, []string) IEvent
Time(string, time.Time) IEvent
Int(string, int) IEvent
Float64(string, float64) IEvent
Array(k string, v *zerolog.Array) (e IEvent)
Dict(k string, v *zerolog.Event) (e IEvent)
// Must not be used on sub-logger init chains.
SendMsgf(string, ...any)
// Must not be used on sub-logger init chains.
SendMsg(string)
// It's like Msg(), but sets the value to "title" field, and also
// can be used to report to metrics. Must be low-cardinality string.
// DO NOT put in it any variable strings, e.g. Sprintf()-formatted or
// containing requestId or any other Id or counters!
// Can't be applied for sub-logger chains, only for events.
// In typical idiom, must be used BEFORE the Msgtag() - it's specififcally
// designed to not bypass in inactive events.
Title(string) IEvent
// The same as Title().Send()
// Must not be used on sub-logger init chains.
SendTitle(string)
// Some first strings are reported to metrics, be careful to NOT put in them
// high-cardinality IDs. Doesn't apply to sub-logger init chains, must be set
// per each event individually.
// If the ActicationHook is set, it is called, and it can reactivate the event.
Msgtag(msgtag *Msgtag, ss ...string) IEvent
// Also must be reported to metrics.
SubSystem(string) IEvent
RequestId(string) IEvent
RawJSON(string, []byte) IEvent
Bytes(string, []byte) IEvent
// Must not be used on sub-logger init chains.
Send()
// Only works if you created a chain with With()
ILogger() ILogger
}
type ILogger ¶
type ILogger interface {
TraceEvent() IEvent
DebugEvent() IEvent
ErrorEvent() IEvent
ErrEvent(error) IEvent
WarnEvent() IEvent
InfoEvent() IEvent
// Can be used if you intend to call ILogger() on it later.
// By default, all new sub-loggers are active, even if parent was inactivated.
SubLoggerInitChain() IEvent
GetZeroLoggerPtr() *zerolog.Logger
// This is useful to access Settings later after init.
GetNutzLogger() *Logger
SetLevel(zerolog.Level) ILogger
// Attach any user object to the event object, to be used later
// inside the callback hooks. Intended to pass user-level runtime data to the
// hook(s). Doesn't add anything to the logline serializations.
// Normally, the UO must be a pointer, and at the receiving side in the hook
// you do something along the lines:
//
// myObject, _ := e.ParentLogger.UserObject.(*MyObject)
// if myObject != nil {
// ...
// }
AddUO(uo any) ILogger
}
type Logger ¶
type Logger struct {
Settings *Settings
IsInactive bool // per whole logger instance
TheSubsystem string // per logger
UserObject any
// contains filtered or unexported fields
}
func New ¶
An initial zerologger must be provided by yours explicitly. Typical idiom:
import(
"github.com/rs/zerolog/log"
)
...
my.Logger = logger.New(&log.Logger, func(s *logger.Settings) {
s.PanicOnMisuse = false
})
func (*Logger) DebugEvent ¶ added in v1.17.0
func (*Logger) ErrorEvent ¶ added in v1.17.0
func (*Logger) GetNutzLogger ¶ added in v1.16.0
func (*Logger) GetZeroLoggerPtr ¶
func (*Logger) SubLoggerInitChain ¶
func (*Logger) TraceEvent ¶ added in v1.17.0
type Msgtag ¶
type Msgtag []string
Few first strings are reported to metrics, be careful to NOT put in them high-cardinality IDs.
func NormalizeTheMsgtag ¶
Click to show internal directories.
Click to hide internal directories.