 6b4db2baef
			
		
	
	6b4db2baef
	
	
	
		
			
			- Try to factorise initialize_logger into redfish.config. - Remove global logger declaration to avoid potential side effects. - Add new logging.debug instead of print and try to cleanup. - Allow logger.setlevel to be more flexible by configuring console and file level of log. - Prepare client to allow optional debug parameter with loglevel selection.
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.4 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=""):
 | |
|     '''Initialize a global logger to track application behaviour
 | |
| 
 | |
|     :param redfish_logfile: Log filename
 | |
|     :type str
 | |
|     :param screen_logger_level: Console log level
 | |
|                                 (logging.DEBUG, logging.ERROR, ..) or nolog
 | |
|     :type logging constant or string
 | |
|     :param file_logger_level: File log level
 | |
|     :type 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
 |