Base di conoscenzaCentro esami
ITItaliano
Scegli la lingua13

CKTIS / Python

logging.getLogger

getLogger restituisce lo stesso logger per un nome nell’interprete e la radice senza nome.

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

Sintassi

logging.getLogger(name=None)

getLogger restituisce lo stesso logger per un nome nell’interprete e la radice senza nome.

I punti formano una gerarchia. Con NOTSET la soglia è cercata negli antenati e un genitore creato in seguito può cambiare il parent di un figlio esistente.

Impostare ERROR tramite a produce True False True nell’esempio.

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)

Esempi

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))

Risultato

True False True

Impostare ERROR tramite a produce True False True nell’esempio.

Fonti