Python/logging: Difference between revisions

From Wiki
(Die Seite wurde neu angelegt: „<pre> import logging import logging.handlers LOG_FILENAME = 'StatusLight.log' log = logging.getLogger('log') log.setLevel(logging.INFO) handler = logging.hand…“)
 
No edit summary
 
Line 1: Line 1:
== Basic with rotation ==
<pre>
<pre>
import logging
import logging

Latest revision as of 15:39, 14 December 2018

Basic with rotation

import logging
import logging.handlers

LOG_FILENAME = 'StatusLight.log'
log = logging.getLogger('log')
log.setLevel(logging.INFO)
handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=5*1024*1024, backupCount=5)
log.addHandler(handler)

log.info("hello")