Skip to content

Commit

Permalink
httplog: rename LoggerMode to Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatczuk committed Feb 17, 2023
1 parent a9038cd commit adc421d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bind/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func HTTPServerConfig(fs *pflag.FlagSet, cfg *forwarder.HTTPServerConfig, prefix
namePrefix+"write-timeout", cfg.WriteTimeout, usagePrefix+"HTTP server write timeout")
fs.VarP(anyflag.NewValueWithRedact[*url.Userinfo](cfg.BasicAuth, &cfg.BasicAuth, forwarder.ParseUserInfo, redactUserinfo),
namePrefix+"basic-auth", "", usagePrefix+"HTTP server basic-auth in the form of `username:password`")
fs.Var(anyflag.NewValue[httplog.LoggerMode](cfg.LogHTTPMode, &cfg.LogHTTPMode, httplog.ParseMode),
fs.Var(anyflag.NewValue[httplog.Mode](cfg.LogHTTPMode, &cfg.LogHTTPMode, httplog.ParseMode),
namePrefix+"log-http", usagePrefix+"log http, one of url, headers, body, error; error mode is default and logs requests with status code >= 500")
}

Expand Down
2 changes: 1 addition & 1 deletion http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type HTTPServerConfig struct {
ReadTimeout time.Duration
ReadHeaderTimeout time.Duration
WriteTimeout time.Duration
LogHTTPMode httplog.LoggerMode
LogHTTPMode httplog.Mode

PromNamespace string
PromRegistry prometheus.Registerer
Expand Down
20 changes: 10 additions & 10 deletions httplog/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import (
"github.com/saucelabs/forwarder/middleware"
)

type LoggerMode string
type Mode string

const (
URLLogMode LoggerMode = "url"
HeadersLogMode LoggerMode = "headers"
BodyLogMode LoggerMode = "body"
ErrOnlyLogMode LoggerMode = "error"
URLLogMode Mode = "url"
HeadersLogMode Mode = "headers"
BodyLogMode Mode = "body"
ErrOnlyLogMode Mode = "error"
)

func (m LoggerMode) Validate() error {
func (m Mode) Validate() error {
switch m {
case URLLogMode, HeadersLogMode, BodyLogMode, ErrOnlyLogMode:
return nil
Expand All @@ -35,8 +35,8 @@ func (m LoggerMode) Validate() error {
return fmt.Errorf("log mode %s not found", m)
}

func ParseMode(val string) (LoggerMode, error) {
mode := LoggerMode(val)
func ParseMode(val string) (Mode, error) {
mode := Mode(val)
switch mode {
case URLLogMode, HeadersLogMode, BodyLogMode, ErrOnlyLogMode:
return mode, nil
Expand All @@ -47,11 +47,11 @@ func ParseMode(val string) (LoggerMode, error) {

type Logger struct {
log func(format string, args ...interface{})
mode LoggerMode
mode Mode
}

// NewLogger returns a logger that logs HTTP requests and responses.
func NewLogger(logFunc func(format string, args ...interface{}), mode LoggerMode) *Logger {
func NewLogger(logFunc func(format string, args ...interface{}), mode Mode) *Logger {
return &Logger{
log: logFunc,
mode: mode,
Expand Down

0 comments on commit adc421d

Please sign in to comment.