git.iko.soy/typeable/oauth2-proxy
on master help sign in
Create Logging FlagSet and Default
commitbbc4eee17ef7a85b332a8cc83bad1195ddde740d authorJoel Speed <joel.speed@hotmail.co.uk> dateTue 12 May 2020, 00:51 (6 years ago) parent3cbac61
2 files changed+52−37
pkg/apis/options/logging.go+49 pkg/apis/options/options.go+3−37
pkg/apis/options/logging.go+49
@@ -1,5 +1,10 @@
11package options
22
3+import (
4+ "github.com/oauth2-proxy/oauth2-proxy/pkg/logger"
5+ "github.com/spf13/pflag"
6+)
7+
38// Logging contains all options required for configuring the logging
49type Logging struct {
510 AuthEnabled bool `flag:"auth-logging" cfg:"auth_logging"`
@@ -22,3 +27,47 @@ type LogFileOptions struct {
2227 MaxBackups int `flag:"logging-max-backups" cfg:"logging_max_backups"`
2328 Compress bool `flag:"logging-compress" cfg:"logging_compress"`
2429}
30+
31+func loggingFlagSet() *pflag.FlagSet {
32+ flagSet := pflag.NewFlagSet("logging", pflag.ExitOnError)
33+
34+ flagSet.Bool("auth-logging", true, "Log authentication attempts")
35+ flagSet.String("auth-logging-format", logger.DefaultAuthLoggingFormat, "Template for authentication log lines")
36+ flagSet.Bool("standard-logging", true, "Log standard runtime information")
37+ flagSet.String("standard-logging-format", logger.DefaultStandardLoggingFormat, "Template for standard log lines")
38+ flagSet.Bool("request-logging", true, "Log HTTP requests")
39+ flagSet.String("request-logging-format", logger.DefaultRequestLoggingFormat, "Template for HTTP request log lines")
40+
41+ flagSet.String("exclude-logging-paths", "", "Exclude logging requests to paths (eg: '/path1,/path2,/path3')")
42+ flagSet.Bool("logging-local-time", true, "If the time in log files and backup filenames are local or UTC time")
43+ flagSet.Bool("silence-ping-logging", false, "Disable logging of requests to ping endpoint")
44+
45+ flagSet.String("logging-filename", "", "File to log requests to, empty for stdout")
46+ flagSet.Int("logging-max-size", 100, "Maximum size in megabytes of the log file before rotation")
47+ flagSet.Int("logging-max-age", 7, "Maximum number of days to retain old log files")
48+ flagSet.Int("logging-max-backups", 0, "Maximum number of old log files to retain; 0 to disable")
49+ flagSet.Bool("logging-compress", false, "Should rotated log files be compressed using gzip")
50+
51+ return flagSet
52+}
53+
54+// loggingDefaults creates a Logging structure, populating each field with its default value
55+func loggingDefaults() Logging {
56+ return Logging{
57+ LocalTime: true,
58+ SilencePing: false,
59+ AuthEnabled: true,
60+ AuthFormat: logger.DefaultAuthLoggingFormat,
61+ RequestEnabled: true,
62+ RequestFormat: logger.DefaultRequestLoggingFormat,
63+ StandardEnabled: true,
64+ StandardFormat: logger.DefaultStandardLoggingFormat,
65+ File: LogFileOptions{
66+ Filename: "",
67+ MaxSize: 100,
68+ MaxAge: 7,
69+ MaxBackups: 0,
70+ Compress: false,
71+ },
72+ }
73+}
pkg/apis/options/options.go+3−37
@@ -9,7 +9,6 @@ import (
99 oidc "github.com/coreos/go-oidc"
1010 ipapi "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/ip"
1111 sessionsapi "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/sessions"
12− "github.com/oauth2-proxy/oauth2-proxy/pkg/logger"
1312 "github.com/oauth2-proxy/oauth2-proxy/providers"
1413 "github.com/spf13/pflag"
1514)
@@ -183,24 +182,7 @@ func NewOptions() *Options {
183182 UserIDClaim: "email",
184183 InsecureOIDCAllowUnverifiedEmail: false,
185184 SkipOIDCDiscovery: false,
186− Logging: Logging{
187− ExcludePaths: "",
188− LocalTime: true,
189− SilencePing: false,
190− AuthEnabled: true,
191− AuthFormat: logger.DefaultAuthLoggingFormat,
192− RequestEnabled: true,
193− RequestFormat: logger.DefaultRequestLoggingFormat,
194− StandardEnabled: true,
195− StandardFormat: logger.DefaultStandardLoggingFormat,
196− File: LogFileOptions{
197− Filename: "",
198− MaxSize: 100,
199− MaxAge: 7,
200− MaxBackups: 0,
201− Compress: false,
202− },
203− },
185+ Logging: loggingDefaults(),
204186 }
205187}
206188
@@ -283,24 +265,6 @@ func NewFlagSet() *pflag.FlagSet {
283265 flagSet.Bool("redis-use-cluster", false, "Connect to redis cluster. Must set --redis-cluster-connection-urls to use this feature")
284266 flagSet.StringSlice("redis-cluster-connection-urls", []string{}, "List of Redis cluster connection URLs (eg redis://HOST[:PORT]). Used in conjunction with --redis-use-cluster")
285267
286− flagSet.String("logging-filename", "", "File to log requests to, empty for stdout")
287− flagSet.Int("logging-max-size", 100, "Maximum size in megabytes of the log file before rotation")
288− flagSet.Int("logging-max-age", 7, "Maximum number of days to retain old log files")
289− flagSet.Int("logging-max-backups", 0, "Maximum number of old log files to retain; 0 to disable")
290− flagSet.Bool("logging-local-time", true, "If the time in log files and backup filenames are local or UTC time")
291− flagSet.Bool("logging-compress", false, "Should rotated log files be compressed using gzip")
292−
293− flagSet.Bool("standard-logging", true, "Log standard runtime information")
294− flagSet.String("standard-logging-format", logger.DefaultStandardLoggingFormat, "Template for standard log lines")
295−
296− flagSet.Bool("request-logging", true, "Log HTTP requests")
297− flagSet.String("request-logging-format", logger.DefaultRequestLoggingFormat, "Template for HTTP request log lines")
298− flagSet.String("exclude-logging-paths", "", "Exclude logging requests to paths (eg: '/path1,/path2,/path3')")
299− flagSet.Bool("silence-ping-logging", false, "Disable logging of requests to ping endpoint")
300−
301− flagSet.Bool("auth-logging", true, "Log authentication attempts")
302− flagSet.String("auth-logging-format", logger.DefaultAuthLoggingFormat, "Template for authentication log lines")
303−
304268 flagSet.String("provider", "google", "OAuth provider")
305269 flagSet.String("provider-display-name", "", "Provider display name")
306270 flagSet.String("oidc-issuer-url", "", "OpenID Connect issuer URL (ie: https://accounts.google.com)")
@@ -326,5 +290,7 @@ func NewFlagSet() *pflag.FlagSet {
326290
327291 flagSet.String("user-id-claim", "email", "which claim contains the user ID")
328292
293+ flagSet.AddFlagSet(loggingFlagSet())
294+
329295 return flagSet
330296}