Skip to content

Instantly share code, notes, and snippets.

@dwickstrom
Created October 21, 2018 09:28
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 dwickstrom/5a501c9b0e125afad538b3c9f225d88f to your computer and use it in GitHub Desktop.
Save dwickstrom/5a501c9b0e125afad538b3c9f225d88f to your computer and use it in GitHub Desktop.
Python logging setup
import sys
import logging
from .config import LOG_LEVEL
def setup_logging():
handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter(
'%(asctime)s [%(levelname)s] @%(threadName)s %(name)s: %(message)s'
)
handler.setFormatter(formatter)
# default logger
default_logger = logging.getLogger()
default_logger.setLevel(getattr(logging, LOG_LEVEL))
default_logger.addHandler(handler)```
if __name__ == ‘__main__‘:
setup_logging()
logger = logging.getLogger(__name__)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment