PageRenderTime 15ms CodeModel.GetById 9ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/django/contrib/logging/__init__.py

https://code.google.com/p/mango-py/
Python | 45 lines | 25 code | 12 blank | 8 comment | 5 complexity | 9467837aca7b2b47cd5d2db65544de70 MD5 | raw file
 1"""The Mango contrib logging module. Just a thin wrapper for python logger"""
 2
 3from django.conf import settings
 4import logging, logging.handlers
 5import os
 6
 7loggers = {}
 8DEBUG=logging.DEBUG
 9INFO=logging.INFO
10WARNING=logging.WARNING
11CRITICAL=logging.CRITICAL
12FATAL=logging.FATAL
13
14def getLogger(name):
15    if name not in loggers:
16        return logging.getLogger(name) #return python root based named logger
17    else:
18        return loggers[name]
19
20def init_logger(name = "mango", logfile = "mango.log"):
21    #print "logging::init_logger(",name,",",logfile,")"
22    fh = logging.handlers.TimedRotatingFileHandler(os.path.join(settings.LOG_DIRECTORY,logfile), 'midnight')
23    fh.setFormatter(settings.LOGGING_FORMATTER)
24    
25    logger = logging.getLogger(name)
26    logger.setLevel(settings.LOGGING_LEVEL)
27    logger.addHandler(fh)
28
29    return logger
30
31def init():
32    """Initialise the logger from the settings file..."""
33    
34    # TODO: improve this
35    for logname in settings.LOGS:
36        loggers[logname] = init_logger(logname, "%s.log"%logname)
37    
38init()
39
40
41
42#logInitDone=False
43#if not logInitDone:
44    #logInitDone = True
45    #init_logging()