Skip to content

Commit

Permalink
Add flags and fix default.
Browse files Browse the repository at this point in the history
Signed-off-by: Dipack Panjabi <[email protected]>
  • Loading branch information
dipack95 committed Feb 23, 2025
1 parent f6327c5 commit 81cdf49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
21 changes: 8 additions & 13 deletions cli/agent/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@ Examples:
`,
}

var accessLog bool
cmd.Flags().BoolVar(
&accessLog,
"access-log",
true,
`
Whether to log all incoming HTTP requests and responses as 'info' logs. For more options, use a configuration file.`,
)
accessLog := log.AccessLogConfig{
Disable: false,
}
flags := cmd.Flags()
accessLog.RegisterFlags(flags, "")

var timeout time.Duration
cmd.Flags().DurationVar(
flags.DurationVar(
&timeout,
"timeout",
time.Second*10,
Expand All @@ -62,10 +59,8 @@ Timeout forwarding incoming HTTP requests to the upstream.`,
EndpointID: args[0],
Addr: args[1],
Protocol: config.ListenerProtocolHTTP,
AccessLog: log.AccessLogConfig{
Enabled: accessLog,
},
Timeout: timeout,
AccessLog: accessLog,
Timeout: timeout,
}}

var err error
Expand Down
8 changes: 6 additions & 2 deletions pkg/log/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,15 @@ func (c *AccessLogConfig) Validate() error {
}

func (c *AccessLogConfig) RegisterFlags(fs *pflag.FlagSet, prefix string) {
prefix = prefix + ".access-log."
if len(prefix) > 0 {
prefix = prefix + ".access-log."
} else {
prefix = "access-log."
}
fs.BoolVar(
&c.Disable,
prefix+"disable",
true,
false,
`
If Access logging is disabled`,
)
Expand Down

0 comments on commit 81cdf49

Please sign in to comment.