Skip to content

Instantly share code, notes, and snippets.

@jorge-lavin
Created October 1, 2014 14:31
Show Gist options
  • Save jorge-lavin/321f474a28476cf4325e to your computer and use it in GitHub Desktop.
Save jorge-lavin/321f474a28476cf4325e to your computer and use it in GitHub Desktop.
prepare_logger
def prepare_logger(options, logging_config_file='logging.ini'):
"""Logging configuration, via logging configuration file and initialization.
@param options: a dictionary with the values of the variables reference in the logging configuration file.
@param logging_config_file: (Optional) If specified, its a full qualified path name to a logging configuration file
@raise IOError: If the logging configuration file is not accesible"""
if logging_config_file:
log_ini_path = logging_config_file
else:
log_ini_path = os.path.join(os.getcwd(), 'logging_config_file')
try:
f = open(log_ini_path,'r')
f.close()
except IOError as io_err:
raise io_err
logging.config.fileConfig(log_ini_path, defaults=options)
global logger
logger = logging.getLogger()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment