mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2024-11-24 08:52:25 +02:00
3fa42edb73
* fix import path for v7 find ./ -name "*.go" | xargs sed -i -e 's|"github.com/oauth2-proxy/oauth2-proxy|"github.com/oauth2-proxy/oauth2-proxy/v7|' * fix module path * go mod tidy * fix installation docs * update CHANGELOG * Update CHANGELOG.md Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk> Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package validation
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
|
|
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
|
|
"gopkg.in/natefinch/lumberjack.v2"
|
|
)
|
|
|
|
// configureLogger is responsible for configuring the logger based on the options given
|
|
func configureLogger(o options.Logging, msgs []string) []string {
|
|
// Setup the log file
|
|
if len(o.File.Filename) > 0 {
|
|
// Validate that the file/dir can be written
|
|
file, err := os.OpenFile(o.File.Filename, os.O_WRONLY|os.O_CREATE, 0600)
|
|
if err != nil {
|
|
if os.IsPermission(err) {
|
|
return append(msgs, "unable to write to log file: "+o.File.Filename)
|
|
}
|
|
}
|
|
err = file.Close()
|
|
if err != nil {
|
|
return append(msgs, "error closing the log file: "+o.File.Filename)
|
|
}
|
|
|
|
logger.Printf("Redirecting logging to file: %s", o.File.Filename)
|
|
|
|
logWriter := &lumberjack.Logger{
|
|
Filename: o.File.Filename,
|
|
MaxSize: o.File.MaxSize, // megabytes
|
|
MaxAge: o.File.MaxAge, // days
|
|
MaxBackups: o.File.MaxBackups,
|
|
LocalTime: o.LocalTime,
|
|
Compress: o.File.Compress,
|
|
}
|
|
|
|
logger.SetOutput(logWriter)
|
|
}
|
|
|
|
// Supply a sanity warning to the logger if all logging is disabled
|
|
if !o.StandardEnabled && !o.AuthEnabled && !o.RequestEnabled {
|
|
logger.Error("Warning: Logging disabled. No further logs will be shown.")
|
|
}
|
|
|
|
// Pass configuration values to the standard logger
|
|
logger.SetStandardEnabled(o.StandardEnabled)
|
|
logger.SetErrToInfo(o.ErrToInfo)
|
|
logger.SetAuthEnabled(o.AuthEnabled)
|
|
logger.SetReqEnabled(o.RequestEnabled)
|
|
logger.SetStandardTemplate(o.StandardFormat)
|
|
logger.SetAuthTemplate(o.AuthFormat)
|
|
logger.SetReqTemplate(o.RequestFormat)
|
|
|
|
logger.SetExcludePaths(o.ExcludePaths)
|
|
|
|
if !o.LocalTime {
|
|
logger.SetFlags(logger.Flags() | logger.LUTC)
|
|
}
|
|
|
|
return msgs
|
|
}
|