Skip to content

Instantly share code, notes, and snippets.

@RavisMsk
Created February 12, 2016 13:52
Show Gist options
  • Save RavisMsk/d23cd6a3903c38777262 to your computer and use it in GitHub Desktop.
Save RavisMsk/d23cd6a3903c38777262 to your computer and use it in GitHub Desktop.
Extending Python logging with new levels
# 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