--- virt-cluster/vc/logger.py 2012/08/30 12:48:07 9 +++ virt-cluster/vc/logger.py 2012/08/31 10:40:38 10 @@ -1,45 +1,45 @@ -# -# BonFIRE Virtual Clusters on Federated Clouds Demonstration Kit -# -# Copyright (c) Fundacion Centro Tecnologico de Supercomputacion de Galicia 2012 -# -# License GPL Version 3 -# -# The research leading to these results has received funding from -# the European Community's Seventh Frameqork Programme (FP7/2007-2013) -# under agreement number 257386 -# -# This software is provided with ABSOLUTELY NO WARRANTY -# -# -*- 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()) +# +# BonFIRE Virtual Clusters on Federated Clouds Demonstration Kit +# +# Copyright (c) Fundacion Centro Tecnologico de Supercomputacion de Galicia 2012 +# +# License GPL Version 3 +# +# The research leading to these results has received funding from +# the European Community's Seventh Framework Programme (FP7/2007-2013) +# under agreement number 257386 +# +# This software is provided with ABSOLUTELY NO WARRANTY +# +# -*- 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())