logger.py
Go to the documentation of this file.
00001 # MIT License
00002 #
00003 # Copyright (c) <2015> <Ikergune, Etxetar>
00004 #
00005 # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
00006 # (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
00007 # publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
00008 # subject to the following conditions:
00009 #
00010 # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
00011 #
00012 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00013 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
00014 # FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00015 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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     ## \brief Logging function
00059     # \param Log Level (INFO, DEBUG, WARNING, ERROR, CRITICAL)
00060     # \param Logging data
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


firos
Author(s): IƱigo Gonzalez, igonzalez@ikergune.com
autogenerated on Thu Jun 6 2019 17:51:04