# -*- 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())