I came from SLF4J and Log4J, so this may be the reason that I do not understand how the log works in Python.
I have the following
---- logging.yaml
version: 1
handlers:
console:
class: logging.StreamHandler
level: DEBUG
stream: ext://sys.stderr
formatter: simpleFormatter
file:
class: logging.FileHandler
filename: app.log
mode: w
level: DEBUG
formatter: simpleFormatter
formatters:
simpleFormatter:
format: '%(name)s %(asctime)s %(levelname)s %(message)s'
datefmt: '%d/%m/%Y %H:%M:%S'
root:
level: INFO
handlers: [console, file]
mod:
level: DEBUG
----- mod.py
import logging
def foo ():
log = logging.getLogger ( __name__ )
log.debug ( 'Hello from the module' )
---- main.py
from logging.config import dictConfig
import yaml
with open ( 'logging.yaml' ) as flog:
dictConfig ( yaml.load ( flog ) )
import logging
from mod import foo
if __name__ == '__main__':
log = logging.getLogger ( __name__ )
log.debug ( 'Hello from main' )
foo ()
With the above configuration, I expect to see only the message 'Hello from the module'. Instead, nothing is printed. When I install DEBUGfor the root logger, both messages are printed.
So, aren't messages redirected to the upper registrars? Is the journal a modchild root? Does logger write the modconfiguration handlers? (I tried to repeat handlersin mod, but nothing changes).
, : INFO, DEBUG, , root?