axiaoxin-com / logging Goto Github PK
View Code? Open in Web Editor NEWmod: zap logging in golang
Home Page: https://godoc.org/github.com/axiaoxin-com/logging
License: MIT License
mod: zap logging in golang
Home Page: https://godoc.org/github.com/axiaoxin-com/logging
License: MIT License
比如接口传过来一个自定义的header abc值为111,我想在记录的log里新增一个字段为abc值为111。怎么配置或者实现呢?
RT
`type GinLoggerConfig struct {
// Optional. Default value is logging.defaultGinLogFormatter
Formatter func(context.Context, GinLogDetails) string
// SkipPaths is a url path array which logs are not written.
// Optional.
SkipPaths []string
// SkipPathRegexps skip path by regexp
SkipPathRegexps []string
// TraceIDFunc 获取或生成 trace id 的函数
// Optional.
TraceIDFunc func(context.Context) string
// InitFieldsFunc 获取 logger 初始字段方法 key 为字段名 value 为字段值
InitFieldsFunc func(context.Context) map[string]interface{}
// 是否使用详细模式打印日志,记录更多字段信息
// Optional.
EnableDetails bool
// 以下选项开启后对性能有影响,适用于接口调试,慎用。
// 是否打印 context keys
// Optional.
EnableContextKeys bool
// 是否打印请求头信息
// Optional.
EnableRequestHeader bool
// 是否打印请求form信息
// Optional.
EnableRequestForm bool
// 是否打印请求体信息
// Optional.
EnableRequestBody bool
// 是否打印响应体信息
// Optional.
EnableResponseBody bool
// 慢请求时间阈值 请求处理时间超过该值则使用 Error 级别打印日志
SlowThreshold time.Duration
}`
mv gin_traceid_middleware.go gin.go
重命名全部方法名 包含Gin
traceid 方法支持可变参数
增加gin logger 中间件:
https://hacpai.com/article/1531819038419
https://github.com/gin-gonic/gin/blob/b94d23d1b48d7b5078035ddbab0c3b5df138b827/logger.go#L183
https://github.com/axiaoxin-com/pink-lady/blob/v1.2.1/app/middleware/logrequest.go
https://github.com/gin-contrib/zap/blob/master/zap.go
目前grom 想使用traceId 必须要增加参数才能传递过来,这样对业务入侵改造太大了,怎么能友好的获取每个请求的traceId呢?谢谢
在使用"带 Trace ID 的 CtxLogger"的同时将日志记录到文件,实现日志的定时切割
options := logging.Options{
LumberjackSink: sink,
OutputPaths: []string{"lumberjack:"},
}
这个配置怎么生效
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.