import repository from arizona
[raven.git] / apps / stork / storklog.py
1 #            [option, long option,                   variable,   action,        data,     default,                                    metavar,     description]
2 """arizonaconfig
3     options=[["",     "--storklogdescriptor",        "logdesc",    "store",       "string", "", None,  "Write log messages to a descriptor"]]
4     includes=[]
5 """
6
7 import arizonaconfig
8
9 import logging
10 import logging.handlers
11 import os
12 import sys
13
14 glo_stork_logger = None
15
16 def init():
17     global glo_stork_logger
18     #glo_stork_logger = logging.getLogger('StorkLogger')
19     glo_stork_logger = logging.Logger("StorkLogger", logging.DEBUG)
20     glo_stork_logger.setLevel(logging.DEBUG)
21
22     file_handler = logging.handlers.RotatingFileHandler("/var/log/stork.log", maxBytes=1*1024*1024, backupCount=1)
23     file_handler.setLevel(logging.DEBUG)
24     file_handler.setFormatter(logging.Formatter("%(asctime)s - %(message)s"))
25     glo_stork_logger.addHandler(file_handler)
26
27     logdesc = arizonaconfig.get_option("logdesc")
28     if logdesc:
29         pipe_handler = logging.StreamHandler(os.fdopen(int(logdesc), "w"))
30         file_handler.setLevel(logging.INFO)
31         pipe_handler.setFormatter(logging.Formatter("%(message)s"))
32         glo_stork_logger.addHandler(pipe_handler)
33
34 def debug(x):
35     if glo_stork_logger:
36         glo_stork_logger.debug(x)
37
38 def info(x):
39     if glo_stork_logger:
40         glo_stork_logger.info(x)
41
42 def warn(x):
43     if glo_stork_logger:
44         glo_stork_logger.warn(x)
45
46 def error(x):
47     if glo_stork_logger:
48         glo_stork_logger.error(x)
49
50 def critical(x):
51     if glo_stork_logger:
52         glo_stork_logger.critical(x)