Skip to content

Instantly share code, notes, and snippets.

@yeonsh
Created January 10, 2015 12:08
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 yeonsh/4b3e59d3fc2fdb21c122 to your computer and use it in GitHub Desktop.
Save yeonsh/4b3e59d3fc2fdb21c122 to your computer and use it in GitHub Desktop.
Python logging
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# create a file handler
handler = logging.FileHandler('hello.log')
handler.setLevel(logging.INFO)
# create a logging format
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
# add the handlers to the logger
logger.addHandler(handler)
logger.info('Hello baby')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment