I have a logging configuration file for logging to console and a file with different formats and levels. In my python script I can load this configuration and basically console and file output are ok.
I set the file name in the config file as shown below.
Is it possible to set that file name in the python script itself?
python code:
# set up logging logging.config.fileConfig(loginipath) logger = logging.getLogger('sLogger') # log something logger.debug('debug message') logger.info('info message') logger.warn('warn message') logger.error('error message') logger.critical('critical message') logging config file:
[loggers] keys=root,sLogger [handlers] keys=consoleHandler,fileHandler [formatters] keys=fileFormatter,consoleFormatter [logger_root] level=DEBUG handlers=consoleHandler [logger_sLogger] level=DEBUG handlers=consoleHandler,fileHandler qualname=sLogger propagate=0 [handler_consoleHandler] class=StreamHandler level=WARNING formatter=consoleFormatter args=(sys.stdout,) [handler_fileHandler] class=FileHandler level=DEBUG formatter=fileFormatter args=('logfile.log',) [formatter_fileFormatter] format=%(asctime)s - %(name)s - %(levelname)s - %(message)s datefmt= [formatter_consoleFormatter] format=%(levelname)s - %(message)s datefmt=