git.iko.soy/typeable/oauth2-proxy
on master help sign in
Create Logging FlagSet and Default
bbc4eeeJoel Speed
pkg/apis/options/logging.go+49
@@ -1,5 +1,10 @@
1package options
1package options
2
2
3+import (
4+ "github.com/oauth2-proxy/oauth2-proxy/pkg/logger"
5+ "github.com/spf13/pflag"
6+)
7+
3// Logging contains all options required for configuring the logging
8// Logging contains all options required for configuring the logging
4type Logging struct {
9type Logging struct {
5 AuthEnabled bool `flag:"auth-logging" cfg:"auth_logging"`
10 AuthEnabled bool `flag:"auth-logging" cfg:"auth_logging"`
@@ -22,3 +27,47 @@ type LogFileOptions struct {
22 MaxBackups int `flag:"logging-max-backups" cfg:"logging_max_backups"`
27 MaxBackups int `flag:"logging-max-backups" cfg:"logging_max_backups"`
23 Compress bool `flag:"logging-compress" cfg:"logging_compress"`
28 Compress bool `flag:"logging-compress" cfg:"logging_compress"`
24}
29}
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 (
9 oidc "github.com/coreos/go-oidc"
9 oidc "github.com/coreos/go-oidc"
10 ipapi "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/ip"
10 ipapi "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/ip"
11 sessionsapi "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/sessions"
11 sessionsapi "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/sessions"
12− "github.com/oauth2-proxy/oauth2-proxy/pkg/logger"
13 "github.com/oauth2-proxy/oauth2-proxy/providers"
12 "github.com/oauth2-proxy/oauth2-proxy/providers"
14 "github.com/spf13/pflag"
13 "github.com/spf13/pflag"
15)
14)
@@ -183,24 +182,7 @@ func NewOptions() *Options {
183 UserIDClaim: "email",
182 UserIDClaim: "email",
184 InsecureOIDCAllowUnverifiedEmail: false,
183 InsecureOIDCAllowUnverifiedEmail: false,
185 SkipOIDCDiscovery: false,
184 SkipOIDCDiscovery: false,
186− Logging: Logging{
185+ Logging: loggingDefaults(),
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− },
204 }
186 }
205}
187}
206
188
@@ -283,24 +265,6 @@ func NewFlagSet() *pflag.FlagSet {
283 flagSet.Bool("redis-use-cluster", false, "Connect to redis cluster. Must set --redis-cluster-connection-urls to use this feature")
265 flagSet.Bool("redis-use-cluster", false, "Connect to redis cluster. Must set --redis-cluster-connection-urls to use this feature")
284 flagSet.StringSlice("redis-cluster-connection-urls", []string{}, "List of Redis cluster connection URLs (eg redis://HOST[:PORT]). Used in conjunction with --redis-use-cluster")
266 flagSet.StringSlice("redis-cluster-connection-urls", []string{}, "List of Redis cluster connection URLs (eg redis://HOST[:PORT]). Used in conjunction with --redis-use-cluster")
285
267
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−
304 flagSet.String("provider", "google", "OAuth provider")
268 flagSet.String("provider", "google", "OAuth provider")
305 flagSet.String("provider-display-name", "", "Provider display name")
269 flagSet.String("provider-display-name", "", "Provider display name")
306 flagSet.String("oidc-issuer-url", "", "OpenID Connect issuer URL (ie: https://accounts.google.com)")
270 flagSet.String("oidc-issuer-url", "", "OpenID Connect issuer URL (ie: https://accounts.google.com)")
@@ -326,5 +290,7 @@ func NewFlagSet() *pflag.FlagSet {
326
290
327 flagSet.String("user-id-claim", "email", "which claim contains the user ID")
291 flagSet.String("user-id-claim", "email", "which claim contains the user ID")
328
292
293+ flagSet.AddFlagSet(loggingFlagSet())
294+
329 return flagSet
295 return flagSet
330}
296}