Documentation
¶
Index ¶
- Constants
- Variables
- func DebugIndent(msg string, indent int, args ...any)
- func ErrorIndent(msg string, indent int, args ...any)
- func InfoIndent(msg string, indent int, args ...any)
- func Init(logFileNm string, level slog.Leveler) (*os.File, error)
- func Trace(msg string, args ...any)
- func TraceIndent(msg string, indent int, args ...any)
- func WarnIndent(msg string, indent int, args ...any)
- type FileHandler
- func (h *FileHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (h *FileHandler) Handle(ctx context.Context, r slog.Record) error
- func (h *FileHandler) TimeFormat(format string) *FileHandler
- func (h *FileHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *FileHandler) WithGroup(name string) slog.Handler
- type HandlerOptions
- type MultiHandler
- type StderrHandler
- type StdoutHandler
- type StreamHandler
- type StreamType
Constants ¶
const ( LevelTrace = slog.Level(-8) LevelDebug = slog.LevelDebug LevelInfo = slog.LevelInfo LevelWarning = slog.LevelWarn LevelError = slog.LevelError )
Variables ¶
var InfoTransformFunc = func(s string) string {
return s
}
Functions ¶
func DebugIndent ¶
func ErrorIndent ¶
func InfoIndent ¶
func TraceIndent ¶
func WarnIndent ¶
Types ¶
type FileHandler ¶
type FileHandler struct {
// contains filtered or unexported fields
}
FileHandler strips ANSI codes and prepends datetime
func NewFileHandler ¶
func NewFileHandler(w io.Writer, opts *HandlerOptions) *FileHandler
func (*FileHandler) TimeFormat ¶
func (h *FileHandler) TimeFormat(format string) *FileHandler
type HandlerOptions ¶
type HandlerOptions struct {
// AddTime causes the handler to include the timestamp in the output.
AddTime bool
// AddLevel causes the handler to include the log level in the output.
AddLevel bool
// AddSource causes the handler to compute the source code position
// of the log statement and add a SourceKey attribute to the output.
AddSource bool
// AddAttrs causes the handler to include the attributes in the output.
AddAttrs bool
// AddGroups causes the handler to include the groups in the output.
AddGroups bool
// NoColor causes the handler to strip ANSI escape codes from the
// output.
NoColor bool
// Level reports the minimum level to log.
// Levels with lower levels are discarded.
// If nil, the Handler uses [slog.LevelInfo].
// This field is ignored if Enablers is not nil.
Level slog.Leveler
// Enablers is a list of functions that determine whether a log
// record should be logged. If any function returns false,
// the record is discarded. If nil or empty, only the Level
// field is used to determine whether to log a record.
Enablers []func(ctx context.Context, level slog.Level) bool
// ReplaceAttr is called to rewrite each non-group attribute before it is logged.
// The attribute's value has been resolved (see [Value.Resolve]).
// If ReplaceAttr returns a zero Attr, the attribute is discarded.
//
// The built-in attributes with keys "time", "level", "source", and "msg"
// are passed to this function, except that time is omitted
// if zero, and source is omitted if AddSource is false.
//
// The first argument is a list of currently open groups that contain the
// Attr. It must not be retained or modified. ReplaceAttr is never called
// for Group attributes, only their contents. For example, the attribute
// list
//
// Int("a", 1), Group("g", Int("b", 2)), Int("c", 3)
//
// results in consecutive calls to ReplaceAttr with the following arguments:
//
// nil, Int("a", 1)
// []string{"g"}, Int("b", 2)
// nil, Int("c", 3)
//
// ReplaceAttr can be used to change the default keys of the built-in
// attributes, convert types (for example, to replace a `time.Time` with the
// integer seconds since the Unix epoch), sanitize personal information, or
// remove attributes from the output.
ReplaceAttr func(groups []string, a slog.Attr) slog.Attr
}
type MultiHandler ¶
type MultiHandler struct {
// contains filtered or unexported fields
}
MultiHandler is a [Handler] that invokes all the given Handlers. Its Enable method reports whether any of the handlers' Enabled methods return true. Its Handle, WithAttr and WithGroup methods call the corresponding method on each of the enabled handlers.
func NewMultiHandler ¶
func NewMultiHandler(handlers ...slog.Handler) *MultiHandler
NewMultiHandler creates a MultiHandler with the given Handlers.
type StderrHandler ¶
type StderrHandler struct {
// contains filtered or unexported fields
}
func NewStderrHandler ¶
func NewStderrHandler(opts *HandlerOptions) *StderrHandler
func (*StderrHandler) Handle ¶
Handle processes a log record and writes the message to the handler's output
type StdoutHandler ¶
type StdoutHandler struct {
// contains filtered or unexported fields
}
func NewStdoutHandler ¶
func NewStdoutHandler(opts *HandlerOptions) *StdoutHandler
func (*StdoutHandler) Handle ¶
Handle processes a log record and writes the message to the handler's output
type StreamHandler ¶
type StreamHandler struct {
// contains filtered or unexported fields
}
StreamHandler prints only the message text
func NewStreamHandler ¶
func NewStreamHandler(st StreamType, opts *HandlerOptions) *StreamHandler
NewStreamHandler creates a new StreamHandler with the given writer and options
func (*StreamHandler) Handle ¶
Handle processes a log record and writes the message to the handler's output