Python’s five standard logging severities
The Python standard-library logging module defines five named severity levels
plus the NOTSET sentinel. Each level maps to an integer, and a record is only
emitted when its value clears the threshold configured with setLevel. This
reference lists every level, its numeric value and when to reach for it, and a
live filter shows exactly which records a chosen threshold will let through.
How it works
Every log record carries a numeric levelno. When you call log.info(...), the
record is created with value 20. The record is emitted only if its value is
greater than or equal to the logger’s effective level — and then again only if
it clears each attached handler’s own level. Because the named levels are spaced
by 10, you can register intermediate custom levels:
import logging
TRACE = 15
logging.addLevelName(TRACE, "TRACE")
logging.getLogger().setLevel(TRACE) # now DEBUG is hidden but TRACE shows
The root logger defaults to WARNING, so DEBUG and INFO are dropped until
you lower the threshold via logging.basicConfig(level=logging.DEBUG).
Tips and notes
- Use
WARNINGand above for anything an operator needs to see; reserveDEBUGfor local tracing and turn it off in production. exc_info=Trueonerror/exceptioncalls attaches the active traceback.- Setting a logger to
NOTSETmakes it inherit its parent — handy for opting a noisy library logger back into the application’s global level. - Handler and logger levels are independent gates; a
DEBUGlogger with anINFOhandler still dropsDEBUGoutput at the handler.