CKTIS / Python
logging.getLogger
Looks up the named logger in the logging registry of the current interpreter.
Version: Python 3.14; repository image, production runtime not attested
Syntax
logging.getLogger(name=None)Looks up the named logger in the logging registry of the current interpreter.
Repeated calls with the same name return the same logger, so updating its level through either reference affects both.
Without a name return the root logger. Dot-separated names create a hierarchy, and a newly created intermediate parent can become an existing child's parent. A child at NOTSET inherits its effective threshold. Reusing work.sample shares its ERROR level, giving True False True.
import logging
child=logging.getLogger('ref.sample.leaf')
parent=logging.getLogger('ref.sample')
assert child.parent is parent and logging.getLogger() is logging.getLogger(None)
assert child is logging.getLogger('ref.sample.leaf')
parent.setLevel(logging.ERROR)
assert child.getEffectiveLevel()==logging.ERROR and not child.isEnabledFor(logging.WARNING)
Examples
import logging
a = logging.getLogger("work.sample")
b = logging.getLogger("work.sample")
a.setLevel(logging.ERROR)
print(a is b, b.isEnabledFor(logging.INFO), b.isEnabledFor(logging.ERROR))
Result
True False True
Without a name return the root logger. Dot-separated names create a hierarchy, and a newly created intermediate parent can become an existing child's parent. A child at NOTSET inherits its effective threshold. Reusing work.sample shares its ERROR level, giving True False True.