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 Logger
- type Option
- func WithAddSource(addSource bool) Option
- func WithCallerSkip(skip int) Option
- func WithCompress(compress bool) Option
- func WithFilename(filename string) 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
}
Config holds the configuration for the logger.
type Logger ¶
Logger wraps the slog.Logger.
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 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.
Click to show internal directories.
Click to hide internal directories.