Skip to content

Instantly share code, notes, and snippets.

@sfdc-afraley
Created July 21, 2020 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfdc-afraley/0780e431de04aeeb78541909c417dffb to your computer and use it in GitHub Desktop.
Save sfdc-afraley/0780e431de04aeeb78541909c417dffb to your computer and use it in GitHub Desktop.
""" Example using the Python logger """
import logging
def main():
""" MAIN """
init_logger(debug=True)
logging.info('Hey this message is important and is always outputted')
some_var = 123545
logging.debug('This is only important when debugging')
logging.debug('Here is the value of some variable: %s', some_var)
logging.error('SOMETHING WENT WRONG ALERT ALL THE THINGS!')
def init_logger(debug=False):
""" Start the python logger """
log_format = '%(asctime)s %(levelname)-8s %(message)s'
if debug:
level = logging.DEBUG
else:
level = logging.INFO
logging.basicConfig(level=level, format=log_format)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment