Add logger package with performance benchmarks

This commit is contained in:
loveuer
2026-01-17 17:27:33 +08:00
parent f7160ce416
commit 507a67e455
7 changed files with 1105 additions and 0 deletions

75
logger/options.go Normal file
View File

@@ -0,0 +1,75 @@
package logger
type options struct {
level Level
format Format
output Output
outputFile string
caller bool
fieldKey string
prefix string
timeFormat string
}
type Option func(*options)
func WithLevel(level Level) Option {
return func(o *options) {
o.level = level
}
}
func WithFormat(format Format) Option {
return func(o *options) {
o.format = format
}
}
func WithOutput(output Output) Option {
return func(o *options) {
o.output = output
}
}
func WithOutputFile(file string) Option {
return func(o *options) {
o.outputFile = file
}
}
func WithCaller(caller bool) Option {
return func(o *options) {
o.caller = caller
}
}
func WithFieldKey(key string) Option {
return func(o *options) {
o.fieldKey = key
}
}
func WithPrefix(prefix string) Option {
return func(o *options) {
o.prefix = prefix
}
}
func WithTimeFormat(format string) Option {
return func(o *options) {
o.timeFormat = format
}
}
func defaultOptions() options {
return options{
level: INFO,
format: TEXT,
output: Stdout,
outputFile: "",
caller: false,
fieldKey: "trace_id",
prefix: "",
timeFormat: "2006-01-02 15:04:05",
}
}