Skip to content

support customize default log field name #10

@dlsrb6342

Description

@dlsrb6342
  • 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))

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions