Documentation
¶
Overview ¶
Package log provides utilities for logging messages to various outputs.
Index ¶
- Constants
- Variables
- type Backend
- type BackendPool
- func (b *BackendPool) AddBackend(back *Backend)
- func (b *BackendPool) Enabled(ctx context.Context, level slog.Level) bool
- func (b *BackendPool) Handle(ctx context.Context, record slog.Record) error
- func (b *BackendPool) NewLogger(name string) *Logger
- func (b *BackendPool) WithAttrs(attrs []slog.Attr) slog.Handler
- func (b *BackendPool) WithGroup(name string) slog.Handler
- type Formatter
- type Level
- type Logger
- func (l *Logger) Alert(text string)
- func (l *Logger) Alertf(text string, args ...any)
- func (l *Logger) AsStdLogger(level Level) *log.Logger
- func (l *Logger) Critical(text string)
- func (l *Logger) Criticalf(text string, args ...any)
- func (l *Logger) Debug(text string)
- func (l *Logger) Debugf(text string, args ...any)
- func (l *Logger) Error(text string)
- func (l *Logger) Errorf(text string, args ...any)
- func (l *Logger) Fatal(text string)
- func (l *Logger) Fatalf(text string, args ...any)
- func (l *Logger) Info(text string)
- func (l *Logger) Infof(text string, args ...any)
- func (l *Logger) Log(level Level, m string)
- func (l *Logger) Notice(text string)
- func (l *Logger) Noticef(text string, args ...any)
- func (l *Logger) Slogger() *slog.Logger
- func (l *Logger) Trace(text string)
- func (l *Logger) Tracef(text string, args ...any)
- func (l *Logger) Warning(text string)
- func (l *Logger) Warningf(text string, args ...any)
- type Record
Constants ¶
const ( Stdout = "stdout" Stderr = "stderr" Discard = "discard" Syslog = "syslog" )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
func NewBackend ¶
NewBackend initializes the logging backend according to the given configuration. If the backend cannot be accessed, an error is returned.
Level represents the minimum logging priority accepted by the backend. Any message with a lower priority will be discarded.
LogTo is the logging output. It can be either: - Stdout - Stderr - Discard - Syslog - a file name
Facility and Tag are only used with a Syslog output. They represent respectively the logging facility and the application's name (in the logging facility).
func (*Backend) NewLogger ¶
NewLogger initiates and returns a new logger with the target Backend as output.
type BackendPool ¶
type BackendPool struct {
// contains filtered or unexported fields
}
BackendPool represent a pool of backends. When instantiating a Logger from a pool of backend, any message written to this Logger will be written to all to backends from the pool. This can be useful if one wishes to send log messages to different outputs depending on the message's level.
func (*BackendPool) AddBackend ¶
func (b *BackendPool) AddBackend(back *Backend)
AddBackend adds a backend to the pool.
func (*BackendPool) Enabled ¶
func (*BackendPool) Handle ¶
func (*BackendPool) NewLogger ¶
func (b *BackendPool) NewLogger(name string) *Logger
NewLogger initiates and returns a new logger with all the pool's backends as output.
func (*BackendPool) WithGroup ¶
func (b *BackendPool) WithGroup(name string) slog.Handler
type Formatter ¶
Formatter is the types of the functions that can be used to format a log entry. They take a pointer to a record and return a formatted string.
type Level ¶
Level represents a logging level. Available levels are: - LevelDebug - LevelInfo - LevelNotice - LevelWarning - LevelError - LevelCritical - LevelAlert - LevelFatal.
const ( LevelTrace Level = -6 LevelDebug Level = Level(slog.LevelDebug) // -4 LevelInfo Level = Level(slog.LevelInfo) // 0 LevelNotice Level = 2 LevelWarning Level = Level(slog.LevelWarn) // 4 LevelError Level = Level(slog.LevelError) // 8 LevelCritical Level = 10 LevelAlert Level = 12 LevelFatal Level = 14 )
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is an internal abstraction of the underlying logging library.
func (*Logger) Alert ¶
Alert logs a message with the Alert level.
func (*Logger) Alertf ¶
Alertf formats the message with given args and logs the result with the. Alert level.
func (*Logger) AsStdLogger ¶
AsStdLogger returns an instance of the standard log.Logger. Any messages written to this standard logger will be written to the source logger with the given level.
func (*Logger) Critical ¶
Critical logs a message with the Critical level.
func (*Logger) Criticalf ¶
Criticalf formats the message with given args and logs the result with the. Critical level.
func (*Logger) Debug ¶
Debug logs a message with the Debug level.
func (*Logger) Debugf ¶
Debugf formats the message with given args and logs the result with the Debug level.
func (*Logger) Error ¶
Error logs a message with the Error level.
func (*Logger) Errorf ¶
Errorf formats the message with given args and logs the result with the Error level.
func (*Logger) Fatal ¶
Fatal logs a message with the Fatal level.
func (*Logger) Fatalf ¶
Fatalf formats the message with given args and logs the result with the Fatal level.
func (*Logger) Infof ¶
Infof formats the message with given args and logs the result with the Info level.
func (*Logger) Log ¶
Log sends a record containing the message `m` to the registered backends whose level is at least `level`.
func (*Logger) Notice ¶
Notice logs a message with the Notice level.
func (*Logger) Noticef ¶
Noticef formats the message with given args and logs the result with the Notice level.
func (*Logger) Trace ¶
Trace logs a message with the Trace level.
func (*Logger) Tracef ¶
Tracef formats the message with given args and logs the result with the Trace level.
func (*Logger) Warning ¶
Warning logs a message with the Warning level.
Source Files
¶
- backend.go
- backend_pool.go
- format.go
- handler.go
- level.go
- level_string.go
- logger.go
- syslog_unix.go