Created
March 28, 2013 13:37
-
-
Save bmacauley/5263168 to your computer and use it in GitHub Desktop.
logging
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
#set up logging | |
logger = logging.getLogger('main') | |
logger.setLevel(logging.DEBUG) | |
# Use file output for production logging: | |
filename, fileextension = os.path.splitext(sys.argv[0]) | |
# log file name <script name>.log | |
log_file = '{0}.log'.format(filename) | |
filelog = logging.FileHandler(log_file, 'a') | |
filelog.setLevel(logging.INFO) | |
# Use console for development logging: | |
conlog = logging.StreamHandler() | |
conlog.setLevel(logging.DEBUG) | |
# Specify log formatting: | |
#formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(module)s - %(lineno)s - %(message)s') | |
formatter = logging.Formatter('%(asctime)s - %(module)s - %(lineno)s - %(levelname)s - %(message)s') | |
conlog.setFormatter(formatter) | |
filelog.setFormatter(formatter) | |
# add console and filelog to logger | |
logger.addHandler(conlog) | |
logger.addHandler(filelog) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment