This is a fork of the exellent Apex Log library.
Main changes:
- Trim unneeded dependencies.
- Make
Fieldsinto a slice to preserve log order. - Split
EntryintoEntryandEntryFields. This is easier to reason about and more effective. - Split the old
Interfacein two and remove all but oneLogmethod (see below). - This allows for lazy creation of messages in
Log(fmt.Stringer)and ignoring fields added inLevelLoggers with levels below theLogger's.
// Logger is the main interface for the logger.
type Logger interface {
// WithLevel returns a new entry with `level` set.
WithLevel(Level) *EntryFields
}
// LevelLogger handles logging for a given level.
type LevelLogger interface {
// Log logs a message at the given level using the string from calling s.String().
// Note that s.String() will not be called if the level is not enabled.
Log(s fmt.Stringer)
// WithLevel returns a new entry with `level` set.
WithLevel(Level) *EntryFields
// WithFields returns a new entry with the`fields` in fields set.
// This is a noop if LevelLogger's level is less than Logger's.
WithFields(fields Fielder) *EntryFields
// WithLevel returns a new entry with the field f set with value v
// This is a noop if LevelLogger's level is less than Logger's.
WithField(f string, v any) *EntryFields
// WithDuration returns a new entry with the "duration" field set
// to the given duration in milliseconds.
// This is a noop if LevelLogger's level is less than Logger's.
WithDuration(time.Duration) *EntryFields
// WithError returns a new entry with the "error" set to `err`.
// This is a noop if err is nil or LevelLogger's level is less than Logger's.
WithError(error) *EntryFields
}