onedns/onedns/logger.py

29 lines
859 B
Python
Raw Normal View History

2016-07-14 16:56:32 +03:00
import logging
import logging.handlers
LOG_FORMAT = ("%(asctime)s %(filename)s:%(lineno)d - %(levelname)s - "
"%(message)s")
log = logging.getLogger('onedns')
2016-07-14 16:56:32 +03:00
console = logging.StreamHandler()
formatter = logging.Formatter(LOG_FORMAT)
console.setFormatter(formatter)
2016-08-03 00:28:44 +03:00
def configure_onedns_logging(debug=False):
2016-07-14 16:56:32 +03:00
"""
Configure logging for onedns *application* code
By default onedns's logger is completely unconfigured so that other
developers using onedns as a library can configure logging as they see fit.
This method is used in onedns's application code (i.e. the 'onedns'
command) to toggle onedns's application specific formatters/handlers
2016-07-14 16:56:32 +03:00
"""
log.setLevel(logging.DEBUG)
2016-07-15 05:28:22 +03:00
if debug:
console.setLevel(logging.DEBUG)
else:
console.setLevel(logging.INFO)
2016-07-14 16:56:32 +03:00
log.addHandler(console)