-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
- we cannot change http, grpc default field name.
- How about adding
LogFieldNamefor customizing log field name?
// http_option.go
var DefaultHttpLogFieldName = &HttpLogFieldName{
Protocol: "protocol",
Path: "path",
Status: "status",
UserAgent: "ua",
RequestedTime: "time",
ElapsedTime: "elapsed(ms)",
QueryString: "qs",
ClientIp: "client-ip",
}
type HttpLogFieldName struct {
Protocol string
Path string
Status string
UserAgent string
RequestedTime string
ElapsedTime string
QueryString string
ClientIp string
}
func WithLogFieldName(logFieldName HttpLogFieldName) httpOption {
return func(cfg *httpConfig) {
cfg.logFieldName = logFieldName
}
}
// http.go
e := le.l.Log().
Str(le.cfg.logFieldName.Protocol, "http").
Str(le.cfg.logFieldName.Path, le.r.URL.Path).
Str(le.cfg.logFieldName.Status, strconv.Itoa(le.ww.Status())).
Str(le.cfg.logFieldName.UserAgent, le.r.UserAgent()).
Str(le.cfg.logFieldName.RequestedTime, t.UTC().Format(time.RFC3339Nano)).
Dur(le.cfg.logFieldName.ElapsedTime, time.Since(t))Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request