Documentation
¶
Index ¶
- func Debug(ctx context.Context, format string, args ...any)
- func Error(ctx context.Context, format string, args ...any)
- func Fatal(ctx context.Context, format string, args ...any)
- func Info(ctx context.Context, format string, args ...any)
- func Log(ctx context.Context, level Level, format string, args ...any)
- func Notice(ctx context.Context, format string, args ...any)
- func Panic(ctx context.Context, format string, args ...any)
- func SetDefault(l Logger)
- func Trace(ctx context.Context, format string, args ...any)
- func Warn(ctx context.Context, format string, args ...any)
- type Handler
- type Handlers
- type Level
- type LevelProvider
- type Logger
- type Option
- type Record
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDefault ¶
func SetDefault(l Logger)
Types ¶
type Handler ¶
type Handler interface { // Output output the log Record. // // 输出日志. Output(Record) }
Handler handles log record, output it to somewhere.
处理日志的接口.
func CombineHandlers ¶ added in v0.0.2
func NewHandler ¶
NewHandler create a new Handler with Info level by default.
创建一个日志处理器, 默认日志级别是 Info.
type LevelProvider ¶ added in v0.0.2
type Logger ¶
type Logger interface { With(key, value any) Logger Trace(ctx context.Context, format string, args ...any) Debug(ctx context.Context, format string, args ...any) Info(ctx context.Context, format string, args ...any) Notice(ctx context.Context, format string, args ...any) Warn(ctx context.Context, format string, args ...any) Error(ctx context.Context, format string, args ...any) Panic(ctx context.Context, format string, args ...any) Fatal(ctx context.Context, format string, args ...any) // Log 打印日志接口 // callDepth: 0=caller position Log(ctx context.Context, callDepth int, level Level, format string, args ...any) }
type Option ¶
type Option func(*handler)
Option Handler options.
日志处理器的配置选项.
func WithFormat ¶ added in v0.0.2
WithFormat set the log format. [experimental] implements by regular expressions, performance may not be very good.
[实验性]设置日志格式. 使用正则表达式实现, 性能可能不是很好.
placeholder args describe %n or %N N/A print a newline %l or %level (-?\d+)? print the log level; the args set print width %F or %FILE N/A print the file name %File or %file %L N/A print the line number %fun N/A print the function name %P / %P[Kk][Gg] N/A print the package name %path N/A print the file path %T (date-format) print time with date-format %t ([num]?s)? print timestampt %X (key-name) print the Attr %X N/A print all Attr %Attr {KV}{prefix}{jointer}{suffix} range print Attr %K print the key %V or %Vjson print the value or json format of the value %M or %m N/A print the log message {left}%or{right} if left is empty then print right %Q or %q (str) print the quote form for str JSON format: {"ts":%t(ns),"time":%Q(%T(2006-01-02T15:04:05.000000000-07:00)),"level":%Q(%level), "pkg":%Q(%Pkg),"fun":%Q(%fun),"path":%Q(%path),"file":%Q(%F),"line":%L, %Attr{%Q(%K):%Vjson}{}{,}{,}"msg":%Q(%m)}%n String format: %T(2006-01-02T15:04:05.000-07:00) %level(-5) {%Pkg}%or{?}.{%fun}%or{?} {%path}%or{?}/{%F}%or{???}:%L %X %m%n
func WithJSON ¶ added in v0.0.2
func WithJSON() Option
WithJSON output the log as json format.
JSON 格式输出.
func WithJson ¶
WithJson is a option. output the log as json format if this option is true.
是否以 json 格式输出.
@deprecated use WithJSON instand.
func WithLevel ¶
WithLevel set the default log level. If you want set deffirent level for diffenrent package, consider use `WithLevels`
设置默认的日志输出级别. 如需为不同包设置不同的日志级别, 请参见 `WithLevels` 选项.
func WithLevels ¶
func WithLevels(levelConfig LevelProvider) Option
WithLevels set log level by package name. if this option is set, the `WithLevel` option would be ignored.
设置不同包的日志级别. 如果设置了该选项,`WithLevel` 选项将被忽略.
@param LevelProvider is a interface, which has a method called `Search`. It returns a log level for a given input package name. 参数 LevelProvider 是一个接口, 为指定的包名返回日志级别.
@see 参见 [trie.Tree](pkg/trie/tree.go) 前缀树
func WithNoColor ¶ added in v0.0.2
func WithNoColor() Option
WithNoColor disable output color.
禁用日志颜色.