improve logger

log file size, rotation policy and compression are now configurable
This commit is contained in:
Nicola Murino
2019-07-31 14:06:55 +02:00
parent fab21dcf51
commit 2a8ab620f3
3 changed files with 26 additions and 12 deletions

20
main.go
View File

@@ -28,17 +28,31 @@ func main() {
confName := "sftpgo.conf"
logSender := "main"
var (
configDir string
logFilePath string
configDir string
logFilePath string
logMaxSize int
logMaxBackups int
logMaxAge int
logCompress bool
logVerbose bool
)
flag.StringVar(&configDir, "config-dir", ".", "Location for SFTPGo config dir. It must contain sftpgo.conf, "+
"the private key for the SFTP server (id_rsa file) and the SQLite database if you use SQLite as data provider. "+
"The server private key will be autogenerated if the user that executes SFTPGo has write access to the config-dir")
flag.StringVar(&logFilePath, "log-file-path", "sftpgo.log", "Location for the log file")
flag.IntVar(&logMaxSize, "log-max-size", 10, "Maximum size in megabytes of the log file before it gets rotated.")
flag.IntVar(&logMaxBackups, "log-max-backups", 5, "Maximum number of old log files to retain")
flag.IntVar(&logMaxAge, "log-max-age", 28, "Maximum number of days to retain old log files")
flag.BoolVar(&logCompress, "log-compress", false, "Determine if the rotated log files should be compressed using gzip")
flag.BoolVar(&logVerbose, "log-verbose", true, "Enable verbose logs")
flag.Parse()
configFilePath := filepath.Join(configDir, confName)
logger.InitLogger(logFilePath, zerolog.DebugLevel)
logLevel := zerolog.DebugLevel
if !logVerbose {
logLevel = zerolog.InfoLevel
}
logger.InitLogger(logFilePath, logMaxSize, logMaxBackups, logMaxAge, logCompress, logLevel)
logger.Info(logSender, "starting SFTPGo, config dir: %v", configDir)
config.LoadConfig(configFilePath)
providerConf := config.GetProviderConf()