Created
February 12, 2016 13:52
-
-
Save RavisMsk/d23cd6a3903c38777262 to your computer and use it in GitHub Desktop.
Extending Python logging with new levels
This file contains 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 it like this: | |
# import app_logging as logging | |
import logging | |
from logging import * | |
GENERIC_LVL_NAME = "GENERIC" #Thats our new mixed-in level | |
GENERIC_LVL = 100 | |
logging.basicConfig( | |
level=logging.WARN, # This can be mapped from ENV if specified | |
format='(%(threadName)-10s) %(message)s' | |
) | |
logging.addLevelName(GENERIC_LVL, GENERIC_LVL_NAME) | |
# Our method for logging on new log level | |
def generic(msg, *args, **kwargs): | |
logging.log(GENERIC_LVL, msg, *args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment