Documentation ¶
Overview ¶
Package slog provides a backend agnostic interface for structured logs
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Fields ¶
Fields is sugar syntax for WithFields() for those who believe log.WithFields(slog.Fields{foo: bar}) is nicer than log.WithFields(map[string]any{foo: var})
type LogLevel ¶
type LogLevel int8
LogLevel represents the level of criticality of a log entry
const ( // UndefinedLevel is a placeholder for the zero-value when no level has been set UndefinedLevel LogLevel = iota // Panic represents a log entry for a fatal problem that could be stoped by defer/recover Panic // Fatal represents a log entry for a problem we can't recover Fatal // Error represents a log entry for a problem we can recover Error // Warn represents a log entry for something that might not a problem but it's worth mentioning Warn // Info represents a log entry just to tell what we are doing Info // Debug represents a log entry that contains information important mostly only to developers Debug // ErrorFieldName is the preferred field label for errors ErrorFieldName = "error" )
type LogWriter ¶
type LogWriter struct {
// contains filtered or unexported fields
}
LogWriter is a io.Writer that calls a given function to log each Write() call
func NewLogWriter ¶
func NewLogWriter(l Logger, fn LogWriterFunc) *LogWriter
NewLogWriter creates a new LogWriter with the given slog.Logger and handler function
type LogWriterFunc ¶
LogWriterFunc is the prototype of the functions used to process and log Write() calls
type Logger ¶
type Logger interface { Debug() Logger // Debug is an alias of WithLevel(Debug) Info() Logger // Info is an alias of WithLevel(Info) Warn() Logger // Warn is an alias of WithLevel(Warn) Error() Logger // Error is an alias of WithLevel(Error) Fatal() Logger // Fatal is an alias of WithLevel(Fatal) Panic() Logger // Panic is an alias of WithLevel(Panic) // Print adds a log entry handled in the manner of fmt.Print Print(...any) // Println adds a log entry handled in the manner of fmt.Println Println(...any) // Printf adds a log entry handled in the manner of fmt.Printf Printf(string, ...any) // WithLevel returns a new log context set to add entries to the specified level WithLevel(LogLevel) Logger // WithStack attaches a call stack a log context WithStack(int) Logger // WithField attaches a field to a log context WithField(string, any) Logger // WithFields attaches a set of fields to a log context WithFields(map[string]any) Logger // Enabled tells if the Logger would actually log Enabled() bool // WithEnabled tells if Enabled but also passes a reference to // the logger for convenience when choosing what to log // // e.g. // if log, ok := logger.Debug().WithEnabled(); ok { // log.Print("Let's write detailed debug stuff") // } elseif log, ok := logger.Info().WithEnabled(); ok { // log.Print("Let's write info stuff instead") // } WithEnabled() (Logger, bool) }
Logger is a backend agnostic interface for structured logs
Click to show internal directories.
Click to hide internal directories.