CKTIS / Python
logging.getLogger
getLogger devolve o mesmo registador para o mesmo nome no intérprete e a raiz quando se omite o nome.
Versão: Python 3.14; repository image, production runtime not attested
Sintaxe
logging.getLogger(name=None)getLogger devolve o mesmo registador para o mesmo nome no intérprete e a raiz quando se omite o nome.
Os pontos formam uma hierarquia. Com NOTSET procura-se o limiar nos ascendentes e criar um pai posteriormente pode alterar o parent de um filho existente.
Definir ERROR através de a produz True False True no exemplo.
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)
Exemplos
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))
Resultado
True False True
Definir ERROR através de a produz True False True no exemplo.