3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-01-11 12:42:34 +01:00

log: configurable file rotation (size & backup count)

This commit is contained in:
James Lu 2016-08-17 22:00:42 -07:00
parent 3b93a521d6
commit affe54b47f
2 changed files with 21 additions and 2 deletions

View File

@ -368,6 +368,17 @@ logging:
"commands":
loglevel: INFO
filerotation:
# Configures optional log file rotation. When enabled, PyLink will create rotate files
# in the format pylink-commands.log, pylink-commands.log.1, pylink-commands.log.2, etc.
# If either max_bytes or backup_count is 0, log rotation will be disabled.
# Max amount of bytes per file, before rotation is done. Defaults to 50 MiB (52428800 bytes).
#max_bytes: 52428800
# Amount of backups to make. Defaults to 5.
#backup_count: 5
changehost:
# This block configures the Changehost plugin. You don't need this if you
# aren't using it.

12
log.py
View File

@ -46,8 +46,16 @@ def makeFileLogger(filename, level=None):
# PyLink instances from overwriting each others' log files.
target = os.path.join(logdir, '%s-%s.log' % (conf.confname, filename))
# TODO: configurable values here
filelogger = logging.handlers.RotatingFileHandler(target, maxBytes=52428800, backupCount=5)
logrotconf = conf.conf.get('logging', {}).get('filerotation', {})
# Max amount of bytes per file, before rotation is done. Defaults to 50 MiB.
maxbytes = logrotconf.get('max_bytes', 52428800)
# Amount of backups to make (e.g. pylink-debug.log, pylink-debug.log.1, pylink-debug.log.2, ...)
# Defaults to 5.
backups = logrotconf.get('backup_count', 5)
filelogger = logging.handlers.RotatingFileHandler(target, maxBytes=maxbytes, backupCount=backups)
filelogger.setFormatter(logformatter)
# If no log level is specified, use the same one as STDOUT.