Add logger package with performance benchmarks
This commit is contained in:
75
logger/options.go
Normal file
75
logger/options.go
Normal 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",
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user