diff --git a/pkg/apis/options/logging.go b/pkg/apis/options/logging.go index 3eb6ddc5..b46a0a05 100644 --- a/pkg/apis/options/logging.go +++ b/pkg/apis/options/logging.go @@ -1,5 +1,10 @@ package options +import ( + "github.com/oauth2-proxy/oauth2-proxy/pkg/logger" + "github.com/spf13/pflag" +) + // Logging contains all options required for configuring the logging type Logging struct { AuthEnabled bool `flag:"auth-logging" cfg:"auth_logging"` @@ -22,3 +27,47 @@ type LogFileOptions struct { MaxBackups int `flag:"logging-max-backups" cfg:"logging_max_backups"` Compress bool `flag:"logging-compress" cfg:"logging_compress"` } + +func loggingFlagSet() *pflag.FlagSet { + flagSet := pflag.NewFlagSet("logging", pflag.ExitOnError) + + flagSet.Bool("auth-logging", true, "Log authentication attempts") + flagSet.String("auth-logging-format", logger.DefaultAuthLoggingFormat, "Template for authentication log lines") + flagSet.Bool("standard-logging", true, "Log standard runtime information") + flagSet.String("standard-logging-format", logger.DefaultStandardLoggingFormat, "Template for standard log lines") + flagSet.Bool("request-logging", true, "Log HTTP requests") + flagSet.String("request-logging-format", logger.DefaultRequestLoggingFormat, "Template for HTTP request log lines") + + flagSet.String("exclude-logging-paths", "", "Exclude logging requests to paths (eg: '/path1,/path2,/path3')") + flagSet.Bool("logging-local-time", true, "If the time in log files and backup filenames are local or UTC time") + flagSet.Bool("silence-ping-logging", false, "Disable logging of requests to ping endpoint") + + flagSet.String("logging-filename", "", "File to log requests to, empty for stdout") + flagSet.Int("logging-max-size", 100, "Maximum size in megabytes of the log file before rotation") + flagSet.Int("logging-max-age", 7, "Maximum number of days to retain old log files") + flagSet.Int("logging-max-backups", 0, "Maximum number of old log files to retain; 0 to disable") + flagSet.Bool("logging-compress", false, "Should rotated log files be compressed using gzip") + + return flagSet +} + +// loggingDefaults creates a Logging structure, populating each field with its default value +func loggingDefaults() Logging { + return Logging{ + LocalTime: true, + SilencePing: false, + AuthEnabled: true, + AuthFormat: logger.DefaultAuthLoggingFormat, + RequestEnabled: true, + RequestFormat: logger.DefaultRequestLoggingFormat, + StandardEnabled: true, + StandardFormat: logger.DefaultStandardLoggingFormat, + File: LogFileOptions{ + Filename: "", + MaxSize: 100, + MaxAge: 7, + MaxBackups: 0, + Compress: false, + }, + } +} diff --git a/pkg/apis/options/options.go b/pkg/apis/options/options.go index e5e509a3..abd96495 100644 --- a/pkg/apis/options/options.go +++ b/pkg/apis/options/options.go @@ -9,7 +9,6 @@ import ( oidc "github.com/coreos/go-oidc" ipapi "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/ip" sessionsapi "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/sessions" - "github.com/oauth2-proxy/oauth2-proxy/pkg/logger" "github.com/oauth2-proxy/oauth2-proxy/providers" "github.com/spf13/pflag" ) @@ -183,24 +182,7 @@ func NewOptions() *Options { UserIDClaim: "email", InsecureOIDCAllowUnverifiedEmail: false, SkipOIDCDiscovery: false, - Logging: Logging{ - ExcludePaths: "", - LocalTime: true, - SilencePing: false, - AuthEnabled: true, - AuthFormat: logger.DefaultAuthLoggingFormat, - RequestEnabled: true, - RequestFormat: logger.DefaultRequestLoggingFormat, - StandardEnabled: true, - StandardFormat: logger.DefaultStandardLoggingFormat, - File: LogFileOptions{ - Filename: "", - MaxSize: 100, - MaxAge: 7, - MaxBackups: 0, - Compress: false, - }, - }, + Logging: loggingDefaults(), } } @@ -283,24 +265,6 @@ func NewFlagSet() *pflag.FlagSet { flagSet.Bool("redis-use-cluster", false, "Connect to redis cluster. Must set --redis-cluster-connection-urls to use this feature") flagSet.StringSlice("redis-cluster-connection-urls", []string{}, "List of Redis cluster connection URLs (eg redis://HOST[:PORT]). Used in conjunction with --redis-use-cluster") - flagSet.String("logging-filename", "", "File to log requests to, empty for stdout") - flagSet.Int("logging-max-size", 100, "Maximum size in megabytes of the log file before rotation") - flagSet.Int("logging-max-age", 7, "Maximum number of days to retain old log files") - flagSet.Int("logging-max-backups", 0, "Maximum number of old log files to retain; 0 to disable") - flagSet.Bool("logging-local-time", true, "If the time in log files and backup filenames are local or UTC time") - flagSet.Bool("logging-compress", false, "Should rotated log files be compressed using gzip") - - flagSet.Bool("standard-logging", true, "Log standard runtime information") - flagSet.String("standard-logging-format", logger.DefaultStandardLoggingFormat, "Template for standard log lines") - - flagSet.Bool("request-logging", true, "Log HTTP requests") - flagSet.String("request-logging-format", logger.DefaultRequestLoggingFormat, "Template for HTTP request log lines") - flagSet.String("exclude-logging-paths", "", "Exclude logging requests to paths (eg: '/path1,/path2,/path3')") - flagSet.Bool("silence-ping-logging", false, "Disable logging of requests to ping endpoint") - - flagSet.Bool("auth-logging", true, "Log authentication attempts") - flagSet.String("auth-logging-format", logger.DefaultAuthLoggingFormat, "Template for authentication log lines") - flagSet.String("provider", "google", "OAuth provider") flagSet.String("provider-display-name", "", "Provider display name") flagSet.String("oidc-issuer-url", "", "OpenID Connect issuer URL (ie: https://accounts.google.com)") @@ -326,5 +290,7 @@ func NewFlagSet() *pflag.FlagSet { flagSet.String("user-id-claim", "email", "which claim contains the user ID") + flagSet.AddFlagSet(loggingFlagSet()) + return flagSet }