Skip to content

Instantly share code, notes, and snippets.

@santosh
Created January 23, 2018 04:04
Show Gist options
  • Save santosh/c4c550e686cce26301fd00a4beee7d14 to your computer and use it in GitHub Desktop.
Save santosh/c4c550e686cce26301fd00a4beee7d14 to your computer and use it in GitHub Desktop.
Simplest form of logging in Python.
import logging
# logging levels
# https://docs.python.org/3.6/library/logging.html#logging-levels
# https://docs.python.org/3.6/library/logging.html#logrecord-attributes
logging.basicConfig(filename='logger.log',
filemode='w',
format='%(lineno)d %(levelname)s: %(asctime)s %(funcName)s %(message)s %(thread)d',
level=logging.WARNING)
logging.debug('This message should go to the log file')
logging.info('I told ya!')
logging.warning('Watch out!')
logging.error('An error occured. Program has halt.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment