Setting up child registrars

Every time I think that I understand the logging module, gremlins appear and change the way it works. (Well, I admit that gremlins can be me changing my code.)

What am I doing wrong here?

> ipython
> import logging
> log = logging.Logger("base")
> log.addHandler(logging.StreamHandler())

> log.critical("Hi")
Hi

> log2 = log.getChild("ment")

> log2.critical("hi")
No handlers could be found for logger "base.ment"

I could have sworn that in the past I could use child registrars without additional configuration ...

+5
source share
2 answers

If you change

log = logging.Logger('base')

to

log = logging.getLogger('base')

then it works:

import logging

log = logging.getLogger('base')
log.addHandler(logging.StreamHandler())
log.critical('Hi')
log2 = log.getChild('ment')
log2.critical('hi')

gives

Hi
hi
+5
source

: .:) , , , - logging.Logger() . , (ex getLogger()) logging.Logger() (ex getChild()), logging.Manager, . Logger logging.Logger() , Logger Manager. log.getChild(), Manager, Manager -external logger, . , log, Manager , , , . , , log log2 , log2 -. , ...

+1

All Articles