Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Default = &Logger{ AddSource: true, IsVerbose: false, IsJSONHandler: false, Level: slog.LevelWarn, ReplaceAttr: defaultReplaceAttrFunc, Output: os.Stderr, }
Default is the default *Logger for the default handler.
Functions ¶
Types ¶
type LogHandler ¶
type LogHandler struct {
// contains filtered or unexported fields
}
LogHandler is a slog.Handler implementation that can be used to log to a file.
func NewHandler ¶
func NewHandler(logger *Logger) LogHandler
type Logger ¶
type Logger struct {
// AddSource indicates whether to add source code location to the log.
AddSource bool
// IsVerbose indicates whether to enable verbose mode. If true, debug level will be enabled.
// If false, only warn and error level will be enabled.
IsVerbose bool
// Level indicates the log level of the handler. If IsVerbose is true, Level will be slog.LevelDebug.
Level slog.Level
// IsJSONHandler indicates whether to use JSON format for log output.
IsJSONHandler bool
// ReplaceAttr is a function that can be used to replace the value of an attribute.
ReplaceAttr func(groups []string, a slog.Attr) slog.Attr
// Output is the writer to write the log to. If nil, os.Stderr will be used.
Output io.Writer
}
func (*Logger) SetJSONHandler ¶
func (o *Logger) SetJSONHandler()
func (*Logger) SetMaxLevel ¶
SetMaxLevel sets the max logging level for logger, default is slog.LevelWarn. if IsVerbose is true, level will be slog.LevelDebug.
func (*Logger) SetReplaceAttrFunc ¶
func (*Logger) SetTextHandler ¶
func (o *Logger) SetTextHandler()
func (*Logger) SetVerbose ¶
func (o *Logger) SetVerbose()
Click to show internal directories.
Click to hide internal directories.