-
Notifications
You must be signed in to change notification settings - Fork 2
/
gen.go
57 lines (51 loc) · 3.3 KB
/
gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package logbus
import (
"os"
"time"
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
type FetchLogContext func() []Field
//go:generate optionGen --option_return_previous=false
func _ConfOptionDeclareWithDefault() interface{} {
return map[string]interface{}{
// log
"LogLevel": (zapcore.Level)(zap.DebugLevel), //@MethodComment(日志级别,默认 zap.DebugLevel)
"Dev": false, // false 输出json格式, true 则输出带颜色的易读log @MethodComment(是否输出带颜色的易读log,默认关闭)
"DefaultChannel": string(SERVERLOG), // 默认的dd_meta_channel @MethodComment(设置默认的dd_meta_channel)
"DefaultTag": string(DefaultTag), // 默认打印的tag @MethodComment(设置默认的tag)
"CallerSkip": 3, // zap logger callerSkip @MethodComment(等于zap.CallerSkip)
"FetchLogContext": FetchLogContext(nil), // 打印日志时,获取额外的field @MethodComment(获取额外的field)
//"LogId": true, // 输出 log id @MethodComment(是否输出log_xid,默认开启) // 日志规范要求必须要有xid 不作为配置放出
"StackLogLevel": (zapcore.Level)(zap.ErrorLevel), //@MethodComment(打印stack的最低级别,默认ErrorLevel stack if level >= StackLogLevel)
// stdout
"BufferedStdout": false, // @MethodComment(输出stdout时使用 logbus.BufferedWriteSyncer)
// WriteSyncer
"WriteSyncer": zapcore.WriteSyncer(os.Stdout), // @MethodComment(输出日志的WriteSyncer,默认为os.Stdout)
"UseSystemClock": false, // @MethodComment(是否使用系统时钟, 默认使用offset时钟)
// monitor
"MonitorOutput": MonitorOutput(Noop), // [Logbus, Noop, Prometheus] @MethodComment(监控输出 Logbus, Noop, Prometheus)
// The Prometheus metrics will be made available on this port: @MethodComment(prometheus监控输出端口,k8s集群保持默认9158端口)
"DefaultPrometheusListenAddress": ":9158",
// This is the endpoint where the Prometheus metrics will be made available ("/metrics" is the default with Prometheus):
"DefaultPrometheusPath": "/metrics", // @MethodComment(prometheus监控输出接口path)
// DefaultPercentiles is the default spread of percentiles/quantiles we maintain for timings / histogram metrics:
"DefaultPercentiles": []float64{0.5, 0.75, 0.99, 1}, //@MethodComment(监控统计耗时的分位值,默认统计耗时的 50%, 75%, 99%, 100% 的分位数)
"DefaultLabel": prometheus.Labels(map[string]string{}), //@MethodComment(监控额外添加的全局label,会在监控指标中显示)
"MonitorTimingMaxAge": time.Duration(time.Minute), // @MethodComment(monitor.Timing数据的最大生命周期)
"EncodeCaller": zapcore.CallerEncoder(nil), // @MethodComment(指定CallerEncoder)
// glog
"PrintAsError": true, //@MethodComment(glog输出field带error时,将日志级别提升到error)
}
}
func init() {
InstallConfWatchDog(func(cc *Conf) {
if cc.DefaultLabel == nil {
panic("DefaultLabel is nil")
}
if cc.MonitorOutput != Prometheus && cc.MonitorOutput != Logbus && cc.MonitorOutput != Noop {
panic("MonitorOutput not match")
}
})
}