Skip to content

Instantly share code, notes, and snippets.

@sfdc-afraley
Created July 21, 2020 18:17
Show Gist options
  • Select an option

  • Save sfdc-afraley/0780e431de04aeeb78541909c417dffb to your computer and use it in GitHub Desktop.

Select an option

Save sfdc-afraley/0780e431de04aeeb78541909c417dffb to your computer and use it in GitHub Desktop.

Revisions

  1. sfdc-afraley created this gist Jul 21, 2020.
    32 changes: 32 additions & 0 deletions python_logger.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    """ 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()