[bonfiredemokit] View of /virt-cluster/vc/logger.py
View of /virt-cluster/vc/logger.py
Parent Directory
| Revision Log
Revision 1 -
( download)
( as text)
( annotate)
Mon Aug 27 11:46:35 2012 UTC
(11 years, 11 months ago)
by agomez
File size: 827 byte(s)
# -*- coding: utf-8 -*-
import logging.handlers
DEFAULT_FORMAT = "%(asctime)s - %(module)s:%(lineno)d - %(levelname)s - %(message)s"
class NullHandler(logging.Handler):
def emit(self, record):
pass
def configure(logfile = None, debug = False, console = False):
log.setLevel(logging.DEBUG)
formatter = logging.Formatter(DEFAULT_FORMAT)
if logfile != None:
rotate = logging.handlers.RotatingFileHandler(logfile,maxBytes=1048576,backupCount=2)
rotate.setFormatter(formatter)
rotate.setLevel(logging.INFO)
if debug:
rotate.setLevel(logging.DEBUG)
log.addHandler(rotate)
if console:
cli = logging.StreamHandler()
cli.setFormatter(formatter)
cli.setLevel(logging.INFO)
if debug:
cli.setLevel(logging.DEBUG)
log.addHandler(cli)
log = logging.getLogger()
log.addHandler(NullHandler())
|