Skip to content

Commit e6a13ee

Browse files
authored
Merge pull request #552 from cybertec-postgresql/525-add-log-rotation-configuration
[!] add log rotation configuration, closes #524 #525 #551
2 parents 2fc2b7d + 7112c8b commit e6a13ee

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

config.example.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,20 @@ connection:
2727
logging:
2828
# log-level:[debug|info|error] Verbosity level for stdout and log file (default: info)
2929
log-level: debug
30-
# log-database-level:[debug|info|error] Verbosity level for database storing (default: info)
30+
# log-database-level:[debug|info|error|none] Verbosity level for database storing (default: info)
3131
log-database-level: debug
3232
# log-file: File name to store logs
3333
log-file: session.log
3434
# log-file-format:[json|text] Format of file logs (default: json)
3535
log-file-format: text
36+
# log-file-rotate Rotate log files
37+
log-file-rotate: true
38+
# log-file-size: Maximum size in MB of the log file before it gets rotated (default: 100)
39+
log-file-size: 10
40+
# log-file-age: Number of days to retain old log files, 0 means forever (default: 0)
41+
log-file-age: 28
42+
# log-file-number: Maximum number of old log files to retain, 0 to retain all (default: 0)
43+
log-file-number: 10
3644

3745
# - Bootstrap Settings -
3846
start:

docs/README.rst

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,24 @@ Command line options
7777
--log-file= File name to store logs
7878
--log-file-format=[json|text] Format of file logs (default: json)
7979
--log-file-rotate Rotate log files
80+
--log-file-size= Maximum size in MB of the log file before it gets rotated (default: 100)
81+
--log-file-age= Number of days to retain old log files, 0 means forever (default: 0)
82+
--log-file-number= Maximum number of old log files to retain, 0 to retain all (default: 0)
8083
8184
Start:
8285
-f, --file= SQL script file to execute during startup
83-
--init Initialize database schema to the latest version and exit.
84-
Can be used with --upgrade
86+
--init Initialize database schema to the latest version and exit. Can be used
87+
with --upgrade
8588
--upgrade Upgrade database to the latest version
86-
--debug Run in debug mode. Only asynchronous chains will be executed
89+
--debug Run in debug mode. Only asynchronous chains will be executed
8790
8891
Resource:
89-
--cron-workers= Number of parallel workers for scheduled chains (default: 16)
90-
--interval-workers= Number of parallel workers for interval chains (default: 16)
91-
--chain-timeout= Abort any chain that takes more than the specified number of
92+
--cron-workers= Number of parallel workers for scheduled chains (default: 16)
93+
--interval-workers= Number of parallel workers for interval chains (default: 16)
94+
--chain-timeout= Abort any chain that takes more than the specified number of
9295
milliseconds
93-
--task-timeout= Abort any task within a chain that takes more than the specified
94-
number of milliseconds
96+
--task-timeout= Abort any task within a chain that takes more than the specified number
97+
of milliseconds
9598
9699
REST:
97100
--rest-port= REST API port (default: 0) [$PGTT_RESTPORT]

internal/config/cmdparser.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ type LoggingOpts struct {
2626
LogFile string `long:"log-file" mapstructure:"log-file" description:"File name to store logs"`
2727
LogFileFormat string `long:"log-file-format" mapstructure:"log-file-format" description:"Format of file logs" choice:"json" choice:"text" default:"json"`
2828
LogFileRotate bool `long:"log-file-rotate" mapstructure:"log-file-rotate" description:"Rotate log files"`
29+
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"`
30+
LogFileAge int `long:"log-file-age" mapstructure:"log-file-age" description:"Number of days to retain old log files, 0 means forever" default:"0"`
31+
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"`
2932
}
3033

3134
// StartOpts specifies the application startup options

internal/log/log.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ func getLogFileWriter(opts config.LoggingOpts) any {
2727
if opts.LogFileRotate {
2828
return &lumberjack.Logger{
2929
Filename: opts.LogFile,
30-
MaxSize: 10, // megabytes after which new file is created
31-
MaxBackups: 10, // number of backups
32-
MaxAge: 7, //days
30+
MaxSize: opts.LogFileSize,
31+
MaxBackups: opts.LogFileNumber,
32+
MaxAge: opts.LogFileAge,
3333
}
3434
}
3535
return opts.LogFile

0 commit comments

Comments
 (0)