Differences

This shows you the differences between two versions of the page.

Link to this comparison view

timerotationlogging [2014/10/26 01:52] (current)
Line 1: Line 1:
 +===== Python logging TimedRotation =====
 +This example using timerotation.in (below) to configure logging rotation every minute
 +<​code>​
 +# 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>​
 +
 +Code to perform logging shown below:
 +
 +<​code>​
 +#​!/​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)
 +</​code>​
 +----
 +* [[pythoninfo|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