Documentation ¶
Index ¶
- func Caller(skip int) (pc uintptr)
- func ForDefault(level string, addSource ...bool)
- func GetPrefix(ctx context.Context) (prefix string)
- func Level(logger *slog.Logger, level string)
- func LevelFromString(level string, def slog.Level) slog.Level
- func MessageReceive(ctx context.Context, handleMessage func(ctx context.Context, msg string)) io.WriteCloser
- func New(opts *Options) *slog.Logger
- func NewHandler(w io.Writer, opts *Options) slog.Handler
- func NewWriter(ctx context.Context) io.Writer
- func Prefix(ctx context.Context, prefix string) context.Context
- func Std(w io.Writer, prefix string) *log.Logger
- type Options
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ForDefault ¶
ForDefault 函数用于设置默认日志记录器的级别和是否添加源信息。
参数:
- level string - 日志级别的字符串表示,例如 "info", "debug" 等。
- addSource ...bool - 可选参数,用于指定是否添加源信息。如果提供,第一个布尔值将被用于设置是否添加源信息。否则根据 level == debug 判断添加源信息。
func LevelFromString ¶
LevelFromString parse the level from string, ignore case
- debug => slog.LevelDebug
- info, information => slog.LevelInfo
- warn, warning => slog.LevelWarn
- error, err => slog.LevelError
- otherwise slog.LevelInfo
func MessageReceive ¶
func NewHandler ¶
NewHandler creates a slog.Handler that writes tinted logs to Writer w, using the default options. If opts is nil, the default options are used.
Types ¶
type Options ¶
type Options struct { // Enable source code location (Default: false) AddSource bool // Minimum level to log (Default: slog.LevelInfo) Level slog.Leveler // ReplaceAttr is called to rewrite each non-group attribute before it is logged. // See https://pkg.go.dev/log/slog#HandlerOptions for details. ReplaceAttr func(groups []string, attr slog.Attr) slog.Attr // Time format (Default: "01/02 15:04:05") TimeFormat string // Disable color (Default: false) NoColor bool }
Options for a slog.Handler that writes tinted logs. A zero Options consists entirely of default values.
Options can be used as a drop-in replacement for slog.HandlerOptions.
Click to show internal directories.
Click to hide internal directories.