c34d85fbc5
- Put in place sphinx mechanism to build documentation. Most of the documentation is generated from python docstrings. - redfish-client.py usage is a bit modified to display a decent documentation. - A link rfclient.py to redfish-client.py was created to allow sphinx parsing. The '-' char is not allowed for module and so sphinx autodoc module. - Note : Copyright may need to be reviewed as well as main.py.
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
# coding=utf-8
|
|
|
|
import logging
|
|
from logging.handlers import RotatingFileHandler
|
|
|
|
# Global variable definition
|
|
|
|
logger = None
|
|
TORTILLADEBUG = True
|
|
REDFISH_LOGFILE = "/var/log/python-redfish/python-redfish.log"
|
|
CONSOLE_LOGGER_LEVEL = logging.DEBUG
|
|
FILE_LOGGER_LEVEL = logging.DEBUG
|
|
|
|
|
|
def initialize_logger(REDFISH_LOGFILE,
|
|
CONSOLE_LOGGER_LEVEL,
|
|
FILE_LOGGER_LEVEL,
|
|
logger_name=None):
|
|
'''Initialize a global logger to track application behaviour
|
|
|
|
:param redfish_logfile: Log filename
|
|
:type redfish_logfile: str
|
|
:param screen_logger_level: Console log level
|
|
(logging.DEBUG, logging.ERROR, ..) or nolog
|
|
:type screen_logger_level: logging constant or string
|
|
:param file_logger_level: File log level
|
|
:type file_logger_level: logging constant
|
|
:returns: logging object
|
|
|
|
'''
|
|
|
|
logger = logging.getLogger(logger_name)
|
|
logger.setLevel(logging.DEBUG)
|
|
formatter = logging.Formatter(
|
|
'%(asctime)s :: %(levelname)s :: %(message)s'
|
|
)
|
|
file_handler = RotatingFileHandler(REDFISH_LOGFILE, 'a', 1000000, 1)
|
|
|
|
# First logger to file
|
|
file_handler.setLevel(FILE_LOGGER_LEVEL)
|
|
file_handler.setFormatter(formatter)
|
|
logger.addHandler(file_handler)
|
|
|
|
# Second logger to console
|
|
if CONSOLE_LOGGER_LEVEL != "nolog":
|
|
steam_handler = logging.StreamHandler()
|
|
steam_handler.setLevel(CONSOLE_LOGGER_LEVEL)
|
|
logger.addHandler(steam_handler)
|
|
return logger
|