Created
October 1, 2015 14:00
-
-
Save jorge-lavin/a2c071995bff2738a271 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import logging_manager # Fix this | |
# Get script file name without extension | |
SCRIPT_FILE_NAME=os.path.splitext(os.path.basename(__file__))[0] | |
#TODO: dot log is only added if used init_logger. | |
# Define the log filename | |
ROTATING_LOG_FILE_NAME = SCRIPT_FILE_NAME + '.log' | |
#Define the warning log filename | |
WARNING_LOG_FILE_NAME = SCRIPT_FILE_NAME + '_warning' + '.log' | |
# Prepare the dictionary with the logging options | |
logging_options = { 'rotating_log_file' : ROTATING_LOG_FILE_NAME, 'warning_log_file': WARNING_LOG_FILE_NAME } | |
#Substitute the _options dictionary with the custom defined one | |
logging_manager._options = logging_options | |
# You only init the logger once and get both loggers. | |
logging_manager.init_logger() | |
logger = logging_manager.get_logger() | |
logger_warning = logging_manager.get_logger('warning_logger') | |
# Random logging to show the behaviour | |
logger.info('foo bar bla bla') | |
logger_warning.warn('warning bla ble bli') | |
logger.debug('debug at rotating') | |
logger_warning.error('error at warning logger') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[loggers] | |
keys=root, warnings | |
[handlers] | |
keys=console,log_file,log_warning | |
[formatters] | |
keys=dev | |
[handler_console] | |
class=StreamHandler | |
level=DEBUG | |
formatter=dev | |
args=(sys.stdout,) | |
[handler_log_file] | |
class=handlers.TimedRotatingFileHandler | |
level=DEBUG | |
formatter=dev | |
args=(r'%(rotating_log_file)s', 'H', 1, 2) | |
[handler_log_warning] | |
class=FileHandler | |
level=DEBUG | |
formatter=dev | |
args=(r'%(warning_log_file)s', 'w') | |
[formatter_dev] | |
format=%(asctime)-19s %(funcName)-30s %(levelname)-7s '%(message)s'- (%(module)s, line %(lineno)s) | |
datefmt=%Y/%m/%d %H:%M:%S | |
[logger_root] | |
level=DEBUG | |
handlers=console, log_file | |
[logger_warnings] | |
level=DEBUG | |
handlers=log_warning | |
propagate=0 | |
qualname=warning_logger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment