Skip to content

Instantly share code, notes, and snippets.

@neerajvashistha
Created February 11, 2022 11:49
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 neerajvashistha/f90f751e1be0772b2af72fc79a39902c to your computer and use it in GitHub Desktop.
Save neerajvashistha/f90f751e1be0772b2af72fc79a39902c to your computer and use it in GitHub Desktop.
logging
import logging
logger = logging.getLogger('handler')
logger.setLevel(logging.DEBUG)
# create file handler which logs even debug messages
fh = logging.FileHandler('handler.log')
fh.setLevel(logging.DEBUG)
# create console handler with a higher log level
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
# add the handlers to the logger
logger.addHandler(fh)
logger.addHandler(ch)
logger.propagate = False
logger.info('Info ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment