初步完成&测试可用
This commit is contained in:
+34
-8
@@ -1,20 +1,39 @@
|
||||
package loggerx
|
||||
|
||||
type loggerOption struct {
|
||||
prefix string
|
||||
format string
|
||||
isGinLog bool
|
||||
isGid bool
|
||||
prefix string // 日志前缀
|
||||
format string // text json
|
||||
dir string // 文件目录
|
||||
isGinLog bool
|
||||
isGid bool
|
||||
traceField string // trace字段
|
||||
errorToInfo bool //
|
||||
}
|
||||
|
||||
func defaultOptions() loggerOption {
|
||||
return loggerOption{
|
||||
format: "json",
|
||||
format: "json",
|
||||
dir: "./log",
|
||||
traceField: "trace_id",
|
||||
}
|
||||
}
|
||||
|
||||
type Option func(*loggerOption)
|
||||
|
||||
// trace字段
|
||||
func SetTraceField(traceField string) Option {
|
||||
return func(o *loggerOption) {
|
||||
o.traceField = traceField
|
||||
}
|
||||
}
|
||||
|
||||
// 错误日志是否写入info日志
|
||||
func SetErrorToInfo() Option {
|
||||
return func(o *loggerOption) {
|
||||
o.errorToInfo = true
|
||||
}
|
||||
}
|
||||
|
||||
// 日志的前缀
|
||||
func SetPrefix(prefix string) Option {
|
||||
return func(o *loggerOption) {
|
||||
@@ -36,10 +55,10 @@ func SetGinLog() Option {
|
||||
}
|
||||
}
|
||||
|
||||
// 文件规则
|
||||
func SetFilePath(path string) Option {
|
||||
// 文件路径
|
||||
func SetDir(dir string) Option {
|
||||
return func(o *loggerOption) {
|
||||
// o.isGinLog = true
|
||||
o.dir = dir
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,4 +70,11 @@ func SetGID() Option {
|
||||
}
|
||||
|
||||
// 文件切割规则
|
||||
// 1.文件大小
|
||||
// 2.时间A(年/月/日/时)
|
||||
// 3.时间B(年/月-日)
|
||||
// 4.时间C(年-月-日-时)
|
||||
// 5.时间D(年-月-日)
|
||||
// func SetFileSplit()
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user