Created
July 11, 2018 15:49
-
-
Save bsolomon1124/a7261126f7399a64d139dbf0b841714d to your computer and use it in GitHub Desktop.
Demonstrates different LogRecord attributes (formatters)
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
"""Demonstrates different LogRecord attributes (formatters). | |
https://docs.python.org/3/library/logging.html#logrecord-attributes | |
""" | |
import logging | |
# Notes | |
# ----- | |
# pathname: this is relative! | |
# created: time in seconds since the epoch as a float | |
# name: this is the only place that uses arg to logging.getLogger() | |
FORMAT = """\ | |
LOG: | |
asctime: %(asctime)s | |
created: %(created)f | |
filename: %(filename)s | |
funcName: %(funcName)s | |
levelname: %(levelname)s | |
levelno: %(levelno)s | |
lineno: %(lineno)d | |
message: %(message)s | |
module: %(module)s | |
msec: %(msecs)d | |
name: %(name)s | |
pathname: %(pathname)s | |
process: %(process)d | |
processName: %(processName)s | |
relativeCreated: %(relativeCreated)d | |
thread: %(thread)d | |
threadName: %(threadName)s | |
------------- | |
""" | |
logging.basicConfig(format=FORMAT) | |
logger = logging.getLogger(__name__) # or, try changing this to a string | |
logger.setLevel(logging.DEBUG) | |
def main(): | |
# 'application' code | |
logger.debug('debug message') | |
logger.info('info message') | |
logger.warn('warn message') | |
logger.error('error message') | |
logger.critical('critical message') | |
if __name__ == '__main__': | |
import sys | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment