1 Star 0 Fork 21

yuexudong / go-admin-core

forked from go-admin-team / go-admin-core 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
options.go 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
lwnmengjing 提交于 2020-12-25 10:39 . 优化logger代码
package logger
import (
"context"
"io"
)
type Option func(*Options)
type Options struct {
// The logging level the logger should log at. default is `InfoLevel`
Level Level
// fields to always be logged
Fields map[string]interface{}
// It's common to set this to a file, or leave it default which is `os.Stderr`
Out io.Writer
// Caller skip frame count for file:line info
CallerSkipCount int
// Alternative options
Context context.Context
// Name logger name
Name string
}
// WithFields set default fields for the logger
func WithFields(fields map[string]interface{}) Option {
return func(args *Options) {
args.Fields = fields
}
}
// WithLevel set default level for the logger
func WithLevel(level Level) Option {
return func(args *Options) {
args.Level = level
}
}
// WithOutput set default output writer for the logger
func WithOutput(out io.Writer) Option {
return func(args *Options) {
args.Out = out
}
}
// WithCallerSkipCount set frame count to skip
func WithCallerSkipCount(c int) Option {
return func(args *Options) {
args.CallerSkipCount = c
}
}
// WithName set name for logger
func WithName(name string) Option {
return func(args *Options) {
args.Name = name
}
}
func SetOption(k, v interface{}) Option {
return func(o *Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, k, v)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/yuexudong/go-admin-core.git
git@gitee.com:yuexudong/go-admin-core.git
yuexudong
go-admin-core
go-admin-core
v1.4.1

搜索帮助

344bd9b3 5694891 D2dac590 5694891