Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support customize default log field name #10

Open
dlsrb6342 opened this issue Dec 14, 2021 · 0 comments
Open

support customize default log field name #10

dlsrb6342 opened this issue Dec 14, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@dlsrb6342
Copy link
Member

  • we cannot change http, grpc default field name.
  • How about adding LogFieldName for 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))
@dlsrb6342 dlsrb6342 added the enhancement New feature or request label Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant