Documentation
¶
Index ¶
- func AddSource(logger *slog.Logger, debugOnly bool)
- func Err(err error) slog.Attr
- func ForDefault(level string, addSource ...bool)
- func GetPrefix(ctx context.Context) (prefix string)
- func Level(logger *slog.Logger, level string)
- func LevelFromString(level string) slog.Level
- func MessageRecive(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 Prefix(ctx context.Context, prefix string) context.Context
- func SetDefault(opts *Options)
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Err ¶
Err returns a tinted (colorized) slog.Attr that will be written in red color by the [tint.Handler]. When used with any other slog.Handler, it behaves as
slog.Any("err", err)
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 MessageRecive ¶ added in v0.0.10
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.
func SetDefault ¶ added in v0.0.20
func SetDefault(opts *Options)
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
DebugSourceOnly 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.