Skip to content

Commit

Permalink
[!] add log rotation configuration, closes #524 #525 #551
Browse files Browse the repository at this point in the history
  • Loading branch information
pashagolub committed Mar 10, 2023
1 parent 2fc2b7d commit 7112c8b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
10 changes: 9 additions & 1 deletion config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,20 @@ connection:
logging:
# log-level:[debug|info|error] Verbosity level for stdout and log file (default: info)
log-level: debug
# log-database-level:[debug|info|error] Verbosity level for database storing (default: info)
# log-database-level:[debug|info|error|none] Verbosity level for database storing (default: info)
log-database-level: debug
# log-file: File name to store logs
log-file: session.log
# log-file-format:[json|text] Format of file logs (default: json)
log-file-format: text
# log-file-rotate Rotate log files
log-file-rotate: true
# log-file-size: Maximum size in MB of the log file before it gets rotated (default: 100)
log-file-size: 10
# log-file-age: Number of days to retain old log files, 0 means forever (default: 0)
log-file-age: 28
# log-file-number: Maximum number of old log files to retain, 0 to retain all (default: 0)
log-file-number: 10

# - Bootstrap Settings -
start:
Expand Down
19 changes: 11 additions & 8 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,24 @@ Command line options
--log-file= File name to store logs
--log-file-format=[json|text] Format of file logs (default: json)
--log-file-rotate Rotate log files
--log-file-size= Maximum size in MB of the log file before it gets rotated (default: 100)
--log-file-age= Number of days to retain old log files, 0 means forever (default: 0)
--log-file-number= Maximum number of old log files to retain, 0 to retain all (default: 0)
Start:
-f, --file= SQL script file to execute during startup
--init Initialize database schema to the latest version and exit.
Can be used with --upgrade
--init Initialize database schema to the latest version and exit. Can be used
with --upgrade
--upgrade Upgrade database to the latest version
--debug Run in debug mode. Only asynchronous chains will be executed
--debug Run in debug mode. Only asynchronous chains will be executed
Resource:
--cron-workers= Number of parallel workers for scheduled chains (default: 16)
--interval-workers= Number of parallel workers for interval chains (default: 16)
--chain-timeout= Abort any chain that takes more than the specified number of
--cron-workers= Number of parallel workers for scheduled chains (default: 16)
--interval-workers= Number of parallel workers for interval chains (default: 16)
--chain-timeout= Abort any chain that takes more than the specified number of
milliseconds
--task-timeout= Abort any task within a chain that takes more than the specified
number of milliseconds
--task-timeout= Abort any task within a chain that takes more than the specified number
of milliseconds
REST:
--rest-port= REST API port (default: 0) [$PGTT_RESTPORT]
Expand Down
3 changes: 3 additions & 0 deletions internal/config/cmdparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type LoggingOpts struct {
LogFile string `long:"log-file" mapstructure:"log-file" description:"File name to store logs"`
LogFileFormat string `long:"log-file-format" mapstructure:"log-file-format" description:"Format of file logs" choice:"json" choice:"text" default:"json"`
LogFileRotate bool `long:"log-file-rotate" mapstructure:"log-file-rotate" description:"Rotate log files"`
LogFileSize int `long:"log-file-size" mapstructure:"log-file-size" description:"Maximum size in MB of the log file before it gets rotated" default:"100"`
LogFileAge int `long:"log-file-age" mapstructure:"log-file-age" description:"Number of days to retain old log files, 0 means forever" default:"0"`
LogFileNumber int `long:"log-file-number" mapstructure:"log-file-number" description:"Maximum number of old log files to retain, 0 to retain all" default:"0"`
}

// StartOpts specifies the application startup options
Expand Down
6 changes: 3 additions & 3 deletions internal/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func getLogFileWriter(opts config.LoggingOpts) any {
if opts.LogFileRotate {
return &lumberjack.Logger{
Filename: opts.LogFile,
MaxSize: 10, // megabytes after which new file is created
MaxBackups: 10, // number of backups
MaxAge: 7, //days
MaxSize: opts.LogFileSize,
MaxBackups: opts.LogFileNumber,
MaxAge: opts.LogFileAge,
}
}
return opts.LogFile
Expand Down

0 comments on commit 7112c8b

Please sign in to comment.