My rotatingfilehandler is set to 512 bytes with three backups. However the file does not rotate and is currently at 3.9MB What am I doing wrong? I am using Ubuntu 10.10, I also have the same code on a couple of Debian images which display the same issue so I assuming it is my code at fault.
[formatters]
keys=simpleFormatter
[loggers]
keys=root,simpleExample
[handlers]
keys=consoleHandler,rfileHandler
[formatter_simpleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt= '%Y-%m-%d %H:%M:%S'
[logger_root]
level=INFO
handlers=consoleHandler,rfileHandler,email
[handler_consoleHandler]
class=StreamHandler
level=INFO
formatter=simpleFormatter
args=(sys.stdout,)
[handler_rfileHandler]
class=handlers.RotatingFileHandler
backupCount=3
maxBytes=512
formatter=simpleFormatter
level=INFO
args=('/blabla/logs/blabla.log',)
[logger_simpleExample]
level=INFO
handlers=consoleHandler
qualname=simpleExample
propagate=0
[handler_email]
class=handlers.SMTPHandler
level=WARNING
formatter=simpleFormatter
args=('target url','sendemail',['erich@*****.com'],'EGIM Outstation Logger',('username','pw'))
I had same problem. Try with :
[handler_rfileHandler]
class=handlers.RotatingFileHandler
formatter=simpleFormatter
level=INFO
args=('/blabla/logs/blabla.log', 'a', 512, 3)
I just had the same problem, with maxBytes
and backupCount
coming from a config file as well.
The following code didn't work:
handler = logging.handlers.RotatingFileHandler(filename = config.get("Logger", 'file'),
maxBytes = config.get("Logger", 'max_file_size'),
backupCount = config.get("Logger", 'files_to_keep'))
It turned out that the problem was the way to get the parameters. The following code that passes integer values instead of strings works perfectly:
handler = logging.handlers.RotatingFileHandler(filename = config.get("Logger", 'file'),
maxBytes = config.getint("Logger", 'max_file_size'),
backupCount = config.getint("Logger", 'files_to_keep'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With