Documentation
¶
Index ¶
- func Debug(msg string, attrs ...any)
- func Debugf(format string, args ...any)
- func Error(msg string, attrs ...any) error
- func Errorf(format string, args ...any) error
- func Info(msg string, attrs ...any)
- func Infof(format string, args ...any)
- func InitDefault(opts ...Option)
- func LevelFromStr(level string) slog.Level
- func NewApacheHandler(w io.Writer, opts *slog.HandlerOptions) slog.Handler
- func Warn(msg string, attrs ...any)
- func Warnf(format string, args ...any)
- type Config
- type Fields
- type Logger
- type Option
- func WithAddSource(addSource bool) Option
- func WithCallerSkip(skip int) Option
- func WithCompress(compress bool) Option
- func WithFileName(filename string, fileOnly bool) Option
- func WithFormat(format string) Option
- func WithLevel(level slog.Level) Option
- func WithLevelStr(level string) Option
- func WithMaxAge(maxAge int) Option
- func WithMaxBackups(maxBackups int) Option
- func WithMaxSize(maxSize int) Option
- func WithWriter(writer io.Writer) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitDefault ¶
func InitDefault(opts ...Option)
InitDefault initializes the default package-level logger and updates the default configuration.
func LevelFromStr ¶
func NewApacheHandler ¶
Types ¶
type Config ¶
type Config struct {
// Filename is the file to write logs to. If empty, writes to stdout.
Filename string
// MaxSize is the maximum size in megabytes of the log file before it gets rotated.
MaxSize int
// MaxBackups is the maximum number of old log files to retain.
MaxBackups int
// MaxAge is the maximum number of days to retain old log files.
MaxAge int
// Compress determines if the rotated log files should be compressed.
Compress bool
// Level is the minimum level to log.
Level slog.Level
// Format is the log output format, "json" or "text".
Format string
// CallerSkip is the number of stack frames to skip to find the caller.
CallerSkip int
// Writer is the custom writer to write logs to.
Writer io.Writer
// AddSource is whether to add source information to the log.
AddSource bool
// FileOnly determines if logs should only be written to file (true) or to both file and terminal (false).
FileOnly bool
}
Config holds the configuration for the logger.
type Fields ¶ added in v1.0.0
type Fields map[string]interface{}
Fields is a map of field names to values for structured logging
type Logger ¶
Logger wraps the slog.Logger.
func (*Logger) WithFields ¶ added in v1.0.0
WithFields returns a new Logger with the given fields attached to all log messages. The fields are converted to slog.Attr and passed to With.
type Option ¶
type Option func(*Config)
Option defines a function that configures the logger.
func WithAddSource ¶
WithAddSource sets whether to add source information to the log.
func WithCallerSkip ¶
WithCallerSkip sets the number of stack frames to skip.
func WithCompress ¶
WithCompress enables or disables log compression.
func WithFileName ¶ added in v1.0.0
WithFilename sets the log filename. If fileOnly is true, logs are written only to the file. If fileOnly is false, logs are written to both the file and terminal (stdout).
func WithLevelStr ¶
func WithMaxAge ¶
WithMaxAge sets the maximum number of days to retain old log files.
func WithMaxBackups ¶
WithMaxBackups sets the maximum number of old log files to retain.
func WithMaxSize ¶
WithMaxSize sets the maximum size of the log file in megabytes.
func WithWriter ¶
WithWriter sets the custom writer for the logger.