Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 import os
00018 import logging
00019 import logging.handlers
00020
00021 from include.constants import LOGLEVEL
00022
00023 _logger = logging.getLogger('firos_logger')
00024
00025 SYSLOG_ADDRESS = '/dev/log'
00026
00027 if LOGLEVEL == 'CRITICAL':
00028 _logger.setLevel(logging.CRITICAL)
00029 elif LOGLEVEL == 'ERROR':
00030 _logger.setLevel(logging.ERROR)
00031 elif LOGLEVEL == 'WARNING':
00032 _logger.setLevel(logging.WARNING)
00033 elif LOGLEVEL == 'DEBUG':
00034 _logger.setLevel(logging.DEBUG)
00035 elif LOGLEVEL == 'INFO':
00036 _logger.setLevel(logging.INFO)
00037
00038 PRIORITIES = {
00039 'CRITICAL': 5,
00040 'ERROR': 3,
00041 'WARNING': 2,
00042 'DEBUG': 1,
00043 'INFO': 0
00044 }
00045 if LOGLEVEL == "NONE":
00046 _levelId = -1
00047 else:
00048 _levelId = PRIORITIES[LOGLEVEL]
00049
00050 if os.path.exists(SYSLOG_ADDRESS):
00051 handler = logging.handlers.SysLogHandler(address=SYSLOG_ADDRESS)
00052 _logger.addHandler(handler)
00053 else:
00054 handler = None
00055
00056
00057 def Log(level, *args):
00058
00059
00060
00061 if PRIORITIES[level] >= _levelId:
00062 text = ""
00063 for arg in args:
00064 text = text + " " + str(arg)
00065 text = text[1:]
00066 if handler is not None:
00067 if level == 'CRITICAL':
00068 _logger.critical(text)
00069 elif level == 'ERROR':
00070 print "error" + text
00071 _logger.error(text)
00072 elif level == 'WARNING':
00073 _logger.warning(text)
00074 print text