Documentation
¶
Overview ¶
Package gologger provides a simple layer for leveled logging in go.
Index ¶
- Constants
- func TrimGologgerLevels() *slog.HandlerOptions
- type Event
- type Logger
- func (l *Logger) Debug() *Event
- func (l *Logger) Enabled(_ context.Context, level slog.Level) bool
- func (l *Logger) Error() *Event
- func (l *Logger) Fatal() *Event
- func (l *Logger) Handle(ctx context.Context, record slog.Record) error
- func (l *Logger) Info() *Event
- func (l *Logger) Log(event *Event)
- func (l *Logger) Print() *Event
- func (l *Logger) SetFormatter(formatter formatter.Formatter)
- func (l *Logger) SetMaxLevel(level levels.Level)
- func (l *Logger) SetTimestamp(timestamp bool, minLevel levels.Level)
- func (l *Logger) SetTimestampWithFormat(timestamp bool, minLevel levels.Level, format string)
- func (l *Logger) SetWriter(writer writer.Writer)
- func (l *Logger) Verbose() *Event
- func (l *Logger) Warning() *Event
- func (l *Logger) WithAttrs(attrs []slog.Attr) slog.Handler
- func (l *Logger) WithGroup(name string) slog.Handler
Constants ¶
const ( LevelTrace = slog.Level(-8) // Most detailed logging (DEBUG-4) LevelVerbose = slog.Level(-6) // More detailed than debug (DEBUG-2) LevelSilent = slog.Level(1) // No label output (INFO+1) LevelFatal = slog.Level(12) // Critical errors causing exit (ERROR+4) )
Custom slog levels that match gologger's level hierarchy. These can be used with any slog handler.
Variables ¶
This section is empty.
Functions ¶
func TrimGologgerLevels ¶ added in v1.1.69
func TrimGologgerLevels() *slog.HandlerOptions
TrimGologgerLevels creates handler options that convert gologger offset levels to clean names e.g., "DEBUG-4" becomes "TRACE", "ERROR+4" becomes "FATAL", "INFO+1" becomes "" (silent)
Types ¶
type Event ¶ added in v1.1.0
type Event struct {
// contains filtered or unexported fields
}
Event is a log event to be written with data
func Warning ¶
func Warning() *Event
Warning writes a warning message on the screen with the default label
func (*Event) MsgFunc ¶ added in v1.1.5
MsgFunc logs a message with lazy evaluation. Useful when computing the message can be resource heavy.
type Logger ¶ added in v1.1.0
type Logger struct {
// contains filtered or unexported fields
}
Logger is a logger for logging structured data in a beautiful and fast manner.
var ( // DefaultLogger is the default logging instance DefaultLogger *Logger )
func (*Logger) Debug ¶ added in v1.1.0
Debug writes an error message on the screen with the default label
func (*Logger) Error ¶ added in v1.1.0
Error writes a error message on the screen with the default label
func (*Logger) Info ¶ added in v1.1.0
Info writes a info message on the screen with the default label
func (*Logger) SetFormatter ¶ added in v1.1.0
SetFormatter sets the formatter instance for a logger
func (*Logger) SetMaxLevel ¶ added in v1.1.0
SetMaxLevel sets the max logging level for logger
func (*Logger) SetTimestamp ¶ added in v1.1.6
SetTimestamp enables/disables automatic or custom timestamp
func (*Logger) SetTimestampWithFormat ¶ added in v1.1.58
func (*Logger) Warning ¶ added in v1.1.0
Warning writes a warning message on the screen with the default label
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
|
|
|
rotatedaily
command
|
|
|
rotatehourly
command
|
|
|
slog
command
Example: using gologger as a log/slog handler.
|
Example: using gologger as a log/slog handler. |
|
tee
command
|
|