Created
October 21, 2018 09:28
-
-
Save dwickstrom/5a501c9b0e125afad538b3c9f225d88f to your computer and use it in GitHub Desktop.
Python logging setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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