For certain modules or functions, I want to have a different format for the logged messages. I have done this in a way that looks a bit hacky: I have set a special Logger, containing a special Handler, that has the right Formatter.Here is a simplified portion of my configuration file:formatters:    dbgMessageFormatter:        format: '[%(name)s] %(message)s'    rawMessageFormatter:        format: '%(message)s'handlers:    debugHandler:        class: logging.StreamHandler        level: DEBUG        formatter: dbgMessageFormatter    rawHandler:        class: logging.StreamHandler        level: DEBUG        formatter: rawMessageFormatterloggers:    dbg:        level: DEBUG        handlers: [debugHandler]    raw:        level: DEBUG        handlers: [rawHandler]The main debugging logger is loaded this way:with open(logging_conf_filename) as f:    logging.config.dictConfig(yaml.load(f))dbg_logger = logging.getLogger(dbg)And for a child (named child in the snippet below) of this dbg logger, I set the other Handler this way:raw_logger = logging.getLogger(raw)l = logging.getLogger(child)l.addHandler(raw_logger.handlers[0])l.propagate = FalseIs there a better, more straightforward way to set this up?
How to properly set a different formatter for a specific logger's child?
python;python 3.x;logging