[bonfiredemokit] Annotation of /virt-cluster/vc/logger.py
Annotation of /virt-cluster/vc/logger.py
Parent Directory
| Revision Log
Revision 9 -
(view)
(download)
(as text)
1 : |
agomez |
9 |
#
|
2 : |
|
|
# BonFIRE Virtual Clusters on Federated Clouds Demonstration Kit
|
3 : |
|
|
#
|
4 : |
|
|
# Copyright (c) Fundacion Centro Tecnologico de Supercomputacion de Galicia 2012
|
5 : |
|
|
#
|
6 : |
|
|
# License GPL Version 3
|
7 : |
|
|
#
|
8 : |
|
|
# The research leading to these results has received funding from
|
9 : |
|
|
# the European Community's Seventh Frameqork Programme (FP7/2007-2013)
|
10 : |
|
|
# under agreement number 257386
|
11 : |
|
|
#
|
12 : |
|
|
# This software is provided with ABSOLUTELY NO WARRANTY
|
13 : |
|
|
#
|
14 : |
agomez |
1 |
# -*- coding: utf-8 -*-
|
15 : |
|
|
import logging.handlers
|
16 : |
|
|
|
17 : |
|
|
DEFAULT_FORMAT = "%(asctime)s - %(module)s:%(lineno)d - %(levelname)s - %(message)s"
|
18 : |
|
|
|
19 : |
|
|
class NullHandler(logging.Handler):
|
20 : |
|
|
def emit(self, record):
|
21 : |
|
|
pass
|
22 : |
|
|
|
23 : |
|
|
def configure(logfile = None, debug = False, console = False):
|
24 : |
|
|
log.setLevel(logging.DEBUG)
|
25 : |
|
|
formatter = logging.Formatter(DEFAULT_FORMAT)
|
26 : |
|
|
if logfile != None:
|
27 : |
|
|
rotate = logging.handlers.RotatingFileHandler(logfile,maxBytes=1048576,backupCount=2)
|
28 : |
|
|
rotate.setFormatter(formatter)
|
29 : |
|
|
rotate.setLevel(logging.INFO)
|
30 : |
|
|
if debug:
|
31 : |
|
|
rotate.setLevel(logging.DEBUG)
|
32 : |
|
|
log.addHandler(rotate)
|
33 : |
|
|
|
34 : |
|
|
if console:
|
35 : |
|
|
cli = logging.StreamHandler()
|
36 : |
|
|
cli.setFormatter(formatter)
|
37 : |
|
|
cli.setLevel(logging.INFO)
|
38 : |
|
|
if debug:
|
39 : |
|
|
cli.setLevel(logging.DEBUG)
|
40 : |
|
|
log.addHandler(cli)
|
41 : |
|
|
|
42 : |
|
|
|
43 : |
|
|
|
44 : |
|
|
log = logging.getLogger()
|
45 : |
|
|
log.addHandler(NullHandler())
|
|