Documentation ¶
Index ¶
- Constants
- func Debug(msg string, args ...any)
- func DebugCtx(ctx context.Context, msg string, args ...any)
- func Debugf(format string, args ...any)
- func Error(msg string, args ...any)
- func ErrorCtx(ctx context.Context, msg string, args ...any)
- func Errorf(format string, args ...any)
- func Info(msg string, args ...any)
- func InfoCtx(ctx context.Context, msg string, args ...any)
- func Infof(format string, args ...any)
- func Log(level Level, msg string, args ...any)
- func LogAttrs(level Level, msg string, attrs ...Attr)
- func LogAttrsCtx(ctx context.Context, level Level, msg string, attrs ...Attr)
- func LogCtx(ctx context.Context, level Level, msg string, args ...any)
- func NewWriter(cfg Config) io.WriteCloser
- func ParseLevel(ls SLevel) slog.Level
- func RegisterLevel(ls SLevel, ln Level)
- func SetDefault(l *Logger)
- func Warn(msg string, args ...any)
- func WarnCtx(ctx context.Context, msg string, args ...any)
- func Warnf(format string, args ...any)
- func WithContext(ctx context.Context, logger *Logger) context.Context
- type Attr
- type Config
- type Handler
- type HandlerOptions
- type Kind
- type Level
- type LevelVar
- type Leveler
- type Logger
- func (l *Logger) Debug(msg string, args ...any)
- func (l *Logger) DebugCtx(ctx context.Context, msg string, args ...any)
- func (l *Logger) Debugf(format string, args ...any)
- func (l *Logger) Enabled(level Level) bool
- func (l *Logger) EnabledCtx(ctx context.Context, level Level) bool
- func (l *Logger) Error(msg string, args ...any)
- func (l *Logger) ErrorCtx(ctx context.Context, msg string, args ...any)
- func (l *Logger) Errorf(format string, args ...any)
- func (l *Logger) Handler() Handler
- func (l *Logger) Info(msg string, args ...any)
- func (l *Logger) InfoCtx(ctx context.Context, msg string, args ...any)
- func (l *Logger) Infof(format string, args ...any)
- func (l *Logger) Log(level Level, msg string, args ...any)
- func (l *Logger) LogAttrs(level Level, msg string, attrs ...Attr)
- func (l *Logger) LogAttrsCtx(ctx context.Context, level Level, msg string, attrs ...Attr)
- func (l *Logger) LogCtx(ctx context.Context, level Level, msg string, args ...any)
- func (l *Logger) Warn(msg string, args ...any)
- func (l *Logger) WarnCtx(ctx context.Context, msg string, args ...any)
- func (l *Logger) Warnf(format string, args ...any)
- func (l *Logger) With(args ...any) *Logger
- func (l *Logger) WithGroup(name string) *Logger
- type Record
- type SLevel
- type Writer
Constants ¶
const ( LevelDebug = slog.LevelDebug LevelInfo = slog.LevelInfo LevelWarn = slog.LevelWarn LevelError = slog.LevelError )
const ( KindAny = slog.KindAny KindBool = slog.KindBool KindDuration = slog.KindDuration KindFloat64 = slog.KindFloat64 KindInt64 = slog.KindInt64 KindString = slog.KindString KindTime = slog.KindTime KindUint64 = slog.KindUint64 KindGroup = slog.KindGroup KindLogValuer = slog.KindLogValuer )
const ( // TimeKey is the key used by the built-in handlers for the time // when the log method is called. The associated Value is a [time.Time]. TimeKey = slog.TimeKey // LevelKey is the key used by the built-in handlers for the level // of the log call. The associated value is a [Level]. LevelKey = slog.LevelKey // MessageKey is the key used by the built-in handlers for the // message of the log call. The associated value is a string. MessageKey = slog.MessageKey // SourceKey is the key used by the built-in handlers for the source file // and line of the log call. The associated value is a string. SourceKey = slog.SourceKey )
const BadKey = "!BADKEY"
Variables ¶
This section is empty.
Functions ¶
func LogAttrsCtx ¶
LogAttrsCtx calls Logger.LogAttrsCtx on the default logger.
func NewWriter ¶
func NewWriter(cfg Config) io.WriteCloser
func ParseLevel ¶
func RegisterLevel ¶
func SetDefault ¶
func SetDefault(l *Logger)
SetDefault makes l the default Logger. After this call, output from the log package's default Logger (as with log.Print, etc.) will be logged at LevelInfo using l's Handler.
Types ¶
type Config ¶
type Config struct { Level SLevel `json:"level,omitempty" yaml:"level,omitempty"` Format string `json:"format,omitempty" yaml:"format,omitempty"` Source bool `json:"source,omitempty" yaml:"source,omitempty"` // only use for default log handler DisableColor bool `json:"disableColor,omitempty" yaml:"disableColor,omitempty"` Filename string `json:"filename,omitempty" yaml:"filename,omitempty"` MaxSize int `json:"maxSize,omitempty" yaml:"maxSize,omitempty"` MaxAge int `json:"maxAge,omitempty" yaml:"maxAge,omitempty"` MaxBackups int `json:"maxBackups,omitempty" yaml:"maxBackups,omitempty"` LocalTime bool `json:"localTime,omitempty" yaml:"localTime,omitempty"` Compress bool `json:"compress,omitempty" yaml:"compress,omitempty"` }
func (*Config) HandlerOptions ¶
func (c *Config) HandlerOptions() *HandlerOptions
type Handler ¶
func NewLogHandler ¶
func NewLogHandler(w io.Writer, opts *HandlerOptions, disableColor bool) Handler
func NewMultiHandler ¶
type HandlerOptions ¶
type HandlerOptions = slog.HandlerOptions
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func FromContext ¶
FromContext retrieves the current logger from the context. If no logger is available, the default logger is returned.
func FromRequest ¶
FromRequest retrieves the current logger from the request. If no logger is available, the default logger is returned.
func NewLoggerSkip ¶
func (*Logger) EnabledCtx ¶
EnabledCtx reports whether l emits log records at the given context and level.
func (*Logger) LogAttrsCtx ¶
LogAttrsCtx is a more efficient version of Logger.Log that accepts only Attrs.
func (*Logger) LogCtx ¶
LogCtx emitting a log record with the current time and the given level and message. The Record's Attrs consist of the Logger's attributes followed by the Attrs specified by args.
The attribute arguments are processed as follows:
- If an argument is an Attr, it is used as is.
- If an argument is a string and this is not the last argument, the following argument is treated as the value and the two are combined into an Attr.
- Otherwise, the argument is treated as a value with key `!BADKEY`.
func (*Logger) WithGroup ¶
WithGroup returns a Logger that starts a group if the name is non-empty. The keys of all attributes added to the Logger will be qualified by the given name. (How that qualification happens depends on the [Handler.WithGroup] method of the Logger's Handler.)
If the name is empty, WithGroup returns the receiver.
type Writer ¶
type Writer struct { // Filename is the file to write logs to. Backup log files will be retained // in the same directory. It uses <processname>-lumberjack.log in // os.TempDir() if empty. Filename string // MaxSize is the maximum size in megabytes of the log file before it gets // rotated. It defaults to 100 megabytes. MaxSize int // MaxAge is the maximum number of days to retain old log files based on the // timestamp encoded in their filename. Note that a day is defined as 24 // hours and may not exactly correspond to calendar days due to daylight // savings, leap seconds, etc. The default is not to remove old log files // based on age. MaxAge int // MaxBackups is the maximum number of old log files to retain. The default // is to retain all old log files (though MaxAge may still cause them to get // deleted.) MaxBackups int // LocalTime determines if the time used for formatting the timestamps in // backup files is the computer's local time. The default is to use UTC // time. LocalTime bool // Compress determines if the rotated log files should be compressed // using gzip. The default is not to perform compression. Compress bool // contains filtered or unexported fields }
func (*Writer) Rotate ¶
Rotate causes Logger to close the existing log file and immediately create a new one. This is a helper function for applications that want to initiate rotations outside of the normal rotation rules, such as in response to SIGHUP. After rotating, this initiates compression and removal of old log files according to the configuration.
func (*Writer) Write ¶
Write implements io.Writer. If a write would cause the log file to be larger than MaxSize, the file is closed, renamed to include a timestamp of the current time, and a new log file is created using the original log file name. If the length of the write is greater than MaxSize, an error is returned.