mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-06 14:20:55 +03:00
improve logger
log file size, rotation policy and compression are now configurable
This commit is contained in:
20
main.go
20
main.go
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user