@@ -23,7 +23,6 @@ import (
2323 "github.com/oauth2-proxy/oauth2-proxy/pkg/requests"
2424 "github.com/oauth2-proxy/oauth2-proxy/pkg/sessions"
2525 "github.com/oauth2-proxy/oauth2-proxy/providers"
26− "gopkg.in/natefinch/lumberjack.v2"
2726)
2827
2928// Validate checks that required options are set and validates those that they
@@ -265,7 +264,7 @@ func Validate(o *options.Options) error {
265264
266265 msgs = parseSignatureKey(o, msgs)
267266 msgs = validateCookieName(o, msgs)
268− msgs = setupLogger(o, msgs)
267+ msgs = configureLogger(o.Logging, o.PingPath, msgs)
269268
270269 if o.ReverseProxy {
271270 parser, err := ip.GetRealClientIPParser(o.RealClientIPHeader)
@@ -273,6 +272,11 @@ func Validate(o *options.Options) error {
273272 msgs = append(msgs, fmt.Sprintf("real_client_ip_header (%s) not accepted parameter value: %v", o.RealClientIPHeader, err))
274273 }
275274 o.SetRealClientIPParser(parser)
275+
276+ // Allow the logger to get client IPs
277+ logger.SetGetClientFunc(func(r *http.Request) string {
278+ return ip.GetClientString(o.GetRealClientIPParser(), r, false)
279+ })
276280 }
277281
278282 if len(msgs) != 0 {
@@ -453,63 +457,6 @@ func validateCookieName(o *options.Options, msgs []string) []string {
453457 return msgs
454458}
455459
456−func setupLogger(o *options.Options, msgs []string) []string {
457− // Setup the log file
458− if len(o.Logging.File.Filename) > 0 {
459− // Validate that the file/dir can be written
460− file, err := os.OpenFile(o.Logging.File.Filename, os.O_WRONLY|os.O_CREATE, 0666)
461− if err != nil {
462− if os.IsPermission(err) {
463− return append(msgs, "unable to write to log file: "+o.Logging.File.Filename)
464− }
465− }
466− file.Close()
467−
468− logger.Printf("Redirecting logging to file: %s", o.Logging.File.Filename)
469−
470− logWriter := &lumberjack.Logger{
471− Filename: o.Logging.File.Filename,
472− MaxSize: o.Logging.File.MaxSize, // megabytes
473− MaxAge: o.Logging.File.MaxAge, // days
474− MaxBackups: o.Logging.File.MaxBackups,
475− LocalTime: o.Logging.LocalTime,
476− Compress: o.Logging.File.Compress,
477− }
478−
479− logger.SetOutput(logWriter)
480− }
481−
482− // Supply a sanity warning to the logger if all logging is disabled
483− if !o.Logging.StandardEnabled && !o.Logging.AuthEnabled && !o.Logging.RequestEnabled {
484− logger.Print("Warning: Logging disabled. No further logs will be shown.")
485− }
486−
487− // Pass configuration values to the standard logger
488− logger.SetStandardEnabled(o.Logging.StandardEnabled)
489− logger.SetAuthEnabled(o.Logging.AuthEnabled)
490− logger.SetReqEnabled(o.Logging.RequestEnabled)
491− logger.SetStandardTemplate(o.Logging.StandardFormat)
492− logger.SetAuthTemplate(o.Logging.AuthFormat)
493− logger.SetReqTemplate(o.Logging.RequestFormat)
494− logger.SetGetClientFunc(func(r *http.Request) string {
495− return ip.GetClientString(o.GetRealClientIPParser(), r, false)
496− })
497−
498− excludePaths := make([]string, 0)
499− excludePaths = append(excludePaths, strings.Split(o.Logging.ExcludePaths, ",")...)
500− if o.Logging.SilencePing {
501− excludePaths = append(excludePaths, o.PingPath)
502− }
503−
504− logger.SetExcludePaths(excludePaths)
505−
506− if !o.Logging.LocalTime {
507− logger.SetFlags(logger.Flags() | logger.LUTC)
508− }
509−
510− return msgs
511−}
512−
513460// jwtIssuer hold parsed JWT issuer info that's used to construct a verifier.
514461type jwtIssuer struct {
515462 issuerURI string