Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

logging.debug

Emits a low-severity diagnostic record, subject to the active logger and handler thresholds.

Version: Python 3.14; repository image, production runtime not attested

Syntax

logging.debug(msg, *args, **kwargs)

Emits a low-severity diagnostic record, subject to the active logger and handler thresholds.

A root threshold of INFO filters debug messages. Lowering it to DEBUG exposes later diagnostic records.

DEBUG is numeric level 10 on the root logger. Passing a template and args defers their string formatting until needed. Argument expressions themselves still run before the call. Use logging.getLogger().isEnabledFor(logging.DEBUG) to guard an expensive computation. A handler with a higher threshold can still discard a root-enabled record.

import io,logging
o=io.StringIO()
logging.basicConfig(stream=o,level=logging.INFO,format='%(message)s',force=True)
seen=[]
class Value:
    def __str__(self): seen.append(1); return 'value'
v=Value()
logging.debug('x=%s',v)
assert not seen and not logging.getLogger().isEnabledFor(logging.DEBUG)
logging.getLogger().setLevel(logging.DEBUG)
assert logging.getLogger().isEnabledFor(logging.DEBUG)
logging.debug('x=%s',v)
assert o.getvalue()=='x=value\n' and seen==[1]

Examples

import logging
from io import StringIO

out = StringIO()
logging.basicConfig(stream=out, level=logging.INFO, format="%(message)s", force=True)
logging.debug("before")
logging.getLogger().setLevel(logging.DEBUG)
logging.debug("after")
print(out.getvalue().strip())

Result

after

DEBUG is numeric level 10 on the root logger. Passing a template and args defers their string formatting until needed. Argument expressions themselves still run before the call. Use logging.getLogger().isEnabledFor(logging.DEBUG) to guard an expensive computation. A handler with a higher threshold can still discard a root-enabled record.

Sources