Python logging TimedRotation

This example using timerotation.in (below) to configure logging rotation every minute

# log.ini

[loggers]
keys=root

[handlers]
keys=default

[formatters]
keys=default

[logger_root]
level=INFO
handlers=default
qualname=(root) # note - this is used in non-root loggers
propagate=1 # note - this is used in non-root loggers
channel=
parent=

[handler_default]
class=handlers.TimedRotatingFileHandler
level=INFO
formatter=default
args=('tr.log', 'm', 1)
filename=tr.log

[formatter_default]
format=F2 %(asctime)s %(pathname)s(%(lineno)d): %(levelname)s %(message)s
datefmt=

Code to perform logging shown below:

#!/usr/bin/python

import os
import sys
import logging
import logging.config
import time

# main
if __name__ == "__main__":	# if main
	print "main"
	logging.config.fileConfig('timerotation.ini')
	moduleName = 'X'
	logger = logging.getLogger(moduleName)
	for i in range(500000):
		logger.info('value = '+str(i))
		time.sleep(5)

* Back to Python

timerotationlogging.txt · Last modified: 2014/10/26 01:52 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0