[lib] ajout des fichiers non suivis

darcs-hash:20090609134320-bd074-f4df3e57ff2a6e60f07e25cda773524c8e20de3c.gz
This commit is contained in:
Antoine Durand-Gasselin 2009-06-09 15:43:20 +02:00
parent dce8ccb6da
commit c2535c1f04
17 changed files with 2346 additions and 0 deletions

36
lib/utils/logs.py Normal file
View file

@ -0,0 +1,36 @@
# -*- coding: utf8 -*-
""" Cr@ns logging : logging utilities for cr@ns scripts
"""
import logging
import os
LOG_FOLDER = "/var/log/crans/"
__version__ = "0.1"
def getFileLogger(name):
LOGGER.warning("getFileLogger is deprecated, use CransFileHandler instead.")
logger = logging.getLogger(name)
hdlr = CransFileHandler(name)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
return logger
class CransFileHandler(logging.FileHandler):
def __init__(self, name):
filepath = os.path.join(LOG_FOLDER, name + ".log")
logging.FileHandler.__init__(self, filepath)
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
self.setFormatter(formatter)
### Un peu de configuration
# On log systematiquement les warning, error, exception sous "crans"
# sur l'ecran.
CRANSLOGGER = logging.getLogger("crans")
CRANSLOGGER.setLevel(logging.WARNING)
streamhdlr = logging.StreamHandler()
streamhdlr.setLevel(logging.ERROR)
streamhdlr.setFormatter(logging.Formatter('%(levelname)s: %(message)s'))
CRANSLOGGER.addHandler(streamhdlr)
CRANSLOGGER.addHandler(CransFileHandler("crans"))
LOGGER = logging.getLogger("crans.logging")