Documentation ¶
Index ¶
- Variables
- func Debug(message string, v ...any)
- func DisableDates()
- func Error(message string, v ...any)
- func Fatal(message string, v ...any)
- func File() string
- func Info(message string, v ...any)
- func IsDebug() bool
- func IsFile() bool
- func IsTrace() bool
- func Loggable(l Level) bool
- func ResetLevelOverrides()
- func SetFormat(newFormat Format)
- func SetLevel(newLevel Level)
- func SetLevelOverride(field string, value string, level Level)
- func SetOutput(w io.Writer)
- func Trace(message string, v ...any)
- func Warn(message string, v ...any)
- type Context
- type Contexter
- type Event
- func (e *Event) Debug(message string, v ...any) *Event
- func (e *Event) Err(err error) *Event
- func (e *Event) Error(message string, v ...any) *Event
- func (e *Event) Fatal(message string, v ...any)
- func (e *Event) Field(key string, value any) *Event
- func (e *Event) FieldIf(key string, value any, level Level) *Event
- func (e *Event) Fields(fields Context) *Event
- func (e *Event) Info(message string, v ...any) *Event
- func (e *Event) IsDebug() bool
- func (e *Event) IsTrace() bool
- func (e *Event) JSON() string
- func (e *Event) Log(l Level, message string, v ...any) *Event
- func (e *Event) Loggable(l Level) bool
- func (e *Event) Render(l Level, message string, v ...any) string
- func (e *Event) String() string
- func (e *Event) Tag(tag string) *Event
- func (e *Event) Time(t time.Time) *Event
- func (e *Event) Timing(f func()) *Event
- func (e *Event) Trace(message string, v ...any) *Event
- func (e *Event) Warn(message string, v ...any) *Event
- func (e *Event) With(contexters ...Contexter) *Event
- type Format
- type Level
Constants ¶
This section is empty.
Variables ¶
var ( DefaultLevel = InfoLevel DefaultFormat = TextFormat DefaultOutput = &peekLogWriter{os.Stderr} )
Defaults for package level variables
Functions ¶
func IsDebug ¶
func IsDebug() bool
IsDebug returns true if the current log level is DebugLevel or below
func Loggable ¶
Loggable returns true if the given log level is lower or equal to the current log level
func ResetLevelOverrides ¶
func ResetLevelOverrides()
ResetLevelOverrides removes all log level overrides
func SetLevelOverride ¶
SetLevelOverride adds a log override for the given field
Types ¶
type Contexter ¶
type Contexter interface {
Context() Context
}
Contexter allows structs to export a key-value pairs in the form of a Context
type Event ¶
type Event struct { Timestamp string `json:"time"` Level Level `json:"level"` Message string `json:"message"` // contains filtered or unexported fields }
Event represents a single log event
func Timing ¶
func Timing(f func()) *Event
Timing runs f and records the time if took to execute it in "time_taken_ms"
func (*Event) FieldIf ¶
FieldIf adds a custom field and value to the log event if the given level is loggable
func (*Event) Log ¶
Log logs the event to the defined output, or does nothing if Render returns an empty string
func (*Event) Loggable ¶
Loggable returns true if the given log level is lower or equal to the current log level
func (*Event) Render ¶
Render returns the rendered log event as a string, or an empty string. The event is only rendered, if either the global log level is >= l, or if the log level in one of the overrides matches the level.
If no overrides are defined (default), the Contexter array is not applied unless the event is actually logged. If overrides are defined, then Contexters have to be applied in any case to determine if they match. This is super complicated, but required for efficiency.
type Format ¶
type Format int
Format is a well-known log format