Created
August 4, 2013 00:22
-
-
Save philangist/6148523 to your computer and use it in GitHub Desktop.
Factory Method for creating logging instances that follow a standard format.
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 logging | |
def logger_factory(name, filename='default'): | |
logger = logging.getLogger(name) | |
logger.setLevel(logging.DEBUG) | |
if filename == 'default': | |
filename = name + '.log' | |
file_handler = logging.FileHandler(filename) | |
format = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s: %(message)s') | |
file_handler.setFormatter(format) | |
logger.addHandler(file_handler) | |
return logger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment