Create Logging FlagSet and Default
This commit is contained in:
		
							parent
							
								
									3cbac6122d
								
							
						
					
					
						commit
						bbc4eee17e
					
				|  | @ -1,5 +1,10 @@ | ||||||
| package options | package options | ||||||
| 
 | 
 | ||||||
|  | import ( | ||||||
|  | 	"github.com/oauth2-proxy/oauth2-proxy/pkg/logger" | ||||||
|  | 	"github.com/spf13/pflag" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
| // Logging contains all options required for configuring the logging
 | // Logging contains all options required for configuring the logging
 | ||||||
| type Logging struct { | type Logging struct { | ||||||
| 	AuthEnabled     bool           `flag:"auth-logging" cfg:"auth_logging"` | 	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"` | 	MaxBackups int    `flag:"logging-max-backups" cfg:"logging_max_backups"` | ||||||
| 	Compress   bool   `flag:"logging-compress" cfg:"logging_compress"` | 	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, | ||||||
|  | 		}, | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -9,7 +9,6 @@ import ( | ||||||
| 	oidc "github.com/coreos/go-oidc" | 	oidc "github.com/coreos/go-oidc" | ||||||
| 	ipapi "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/ip" | 	ipapi "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/ip" | ||||||
| 	sessionsapi "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/sessions" | 	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/oauth2-proxy/oauth2-proxy/providers" | ||||||
| 	"github.com/spf13/pflag" | 	"github.com/spf13/pflag" | ||||||
| ) | ) | ||||||
|  | @ -183,24 +182,7 @@ func NewOptions() *Options { | ||||||
| 		UserIDClaim:                      "email", | 		UserIDClaim:                      "email", | ||||||
| 		InsecureOIDCAllowUnverifiedEmail: false, | 		InsecureOIDCAllowUnverifiedEmail: false, | ||||||
| 		SkipOIDCDiscovery:                false, | 		SkipOIDCDiscovery:                false, | ||||||
| 		Logging: Logging{ | 		Logging:                          loggingDefaults(), | ||||||
| 			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, |  | ||||||
| 			}, |  | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -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.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.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", "google", "OAuth provider") | ||||||
| 	flagSet.String("provider-display-name", "", "Provider display name") | 	flagSet.String("provider-display-name", "", "Provider display name") | ||||||
| 	flagSet.String("oidc-issuer-url", "", "OpenID Connect issuer URL (ie: https://accounts.google.com)") | 	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.String("user-id-claim", "email", "which claim contains the user ID") | ||||||
| 
 | 
 | ||||||
|  | 	flagSet.AddFlagSet(loggingFlagSet()) | ||||||
|  | 
 | ||||||
| 	return flagSet | 	return flagSet | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue