| Message ID | bcd0593418a1217f73f4a6946b13a5b603a58fb5.1735852948.git.joerg.sommer@navimatix.de |
|---|---|
| State | Not Applicable |
| Headers | show |
| Series | [1/2] doc/logging: small clean-up and name environment | expand |
Hi Jörg, On Thu Jan 2, 2025 at 10:23 PM CET, Jörg Sommer via lists.yoctoproject.org wrote: > From: Jörg Sommer <joerg.sommer@navimatix.de> > > To give an example how the YAML format can be used, the example of the > warnings logger should be converted to YAML. In https://docs.python.org/3/library/logging.config.html#logging.config.listen the note says: If you want to send configurations to the listener which don’t disable existing loggers, you will need to use a JSON format for the configuration, which will use dictConfig() for configuration. This method allows you to specify disable_existing_loggers as False in the configuration you send. I believe this is the reason why JSON was used. So the disable_existing_loggers usage in Yaml below is ineffective. > Signed-off-by: Jörg Sommer <joerg.sommer@navimatix.de> > --- > .../bitbake-user-manual-execution.rst | 42 ++++++++----------- > 1 file changed, 18 insertions(+), 24 deletions(-) > > > Is the @ in front of disable_existing_loggers correct? In > https://docs.python.org/3/library/logging.config.html#dictionary-schema-details > it's not given. Or can we remove the whole line? At me it works. > > > diff --git a/doc/bitbake-user-manual/bitbake-user-manual-execution.rst b/doc/bitbake-user-manual/bitbake-user-manual-execution.rst > index 0e20d5933..99b91ba50 100644 > --- a/doc/bitbake-user-manual/bitbake-user-manual-execution.rst > +++ b/doc/bitbake-user-manual/bitbake-user-manual-execution.rst > @@ -728,35 +728,29 @@ bitbake, or set it in ``conf/local.conf``:: > > BB_LOGCONFIG = "hashequiv.json" > > -Another example is this ``warn.json`` file to log all ``WARNING`` and > +Another example is this ``warn.yaml`` file to log all ``WARNING`` and > higher priority messages to a ``warn.log`` file:: > > - { > - "version": 1, > - "formatters": { > - "warnlogFormatter": { > - "()": "bb.msg.BBLogFormatter", > - "format": "%(levelname)s: %(message)s" > - } > - }, > + version: 1 > > - "handlers": { > - "warnlog": { > - "class": "logging.FileHandler", > - "formatter": "warnlogFormatter", > - "level": "WARNING", > - "filename": "warn.log" > - } > - }, > + '@disable_existing_loggers': false > > - "loggers": { > - "BitBake": { > - "handlers": ["warnlog"] > - } > - }, > + formatters: > + warnlogFormatter: > + '()': bb.msg.BBLogFormatter > + format: '%(levelname)s: %(message)s' > > - "@disable_existing_loggers": false This is strange, maybe a typo? We should probably remove the "@" here. Antonin
Hi Antonin, Antonin Godard schrieb am Mo 06. Jan, 10:37 (+0100): > On Thu Jan 2, 2025 at 10:23 PM CET, Jörg Sommer via lists.yoctoproject.org wrote: > > From: Jörg Sommer <joerg.sommer@navimatix.de> > > > > To give an example how the YAML format can be used, the example of the > > warnings logger should be converted to YAML. > > In https://docs.python.org/3/library/logging.config.html#logging.config.listen > the note says: But does this apply here? As far as I understand the code the config gets loaded in * lib/bb/ui/knotty.py:393: logconfigfile, error = server.runCommand([cmd, "BB_LOGCONFIG"]) * lib/bb/ui/knotty.py:424: …, logconfigfile = _log_settings_from_server(server, params.observe_only) * lib/bb/ui/knotty.py:590: conf = bb.msg.setLoggingConfig(logconfig, logconfigfile) And in setLoggingConfig is no difference between JSON and YAML: ``` def setLoggingConfig(defaultconfig, userconfigfile=None): logconfig = copy.deepcopy(defaultconfig) if userconfigfile: with open(os.path.normpath(userconfigfile), 'r') as f: if userconfigfile.endswith('.yml') or userconfigfile.endswith('.yaml'): import yaml userconfig = yaml.safe_load(f) elif userconfigfile.endswith('.json') or userconfigfile.endswith('.cfg'): import json userconfig = json.load(f) else: raise BaseException("Unrecognized file format: %s" % userconfigfile) if userconfig.get('bitbake_merge', True): logconfig = mergeLoggingConfig(logconfig, userconfig) else: # Replace the entire default config logconfig = userconfig ``` The BB_LOGCONFIG never goes to the python function logging.config.fileConfig() which has the behaviour you pointed to. > If you want to send configurations to the listener which don’t disable existing > loggers, you will need to use a JSON format for the configuration, which will > use dictConfig() for configuration. This method allows you to specify > disable_existing_loggers as False in the configuration you send. > > I believe this is the reason why JSON was used. So the disable_existing_loggers > usage in Yaml below is ineffective. > > + formatters: + warnlogFormatter: + '()': bb.msg.BBLogFormatter + > > format: '%(levelname)s: %(message)s' > > > > - "@disable_existing_loggers": false > > This is strange, maybe a typo? We should probably remove the "@" here. Yes, I found nowhere in Python disable_existing_loggers with “@”, and no special handling of it in BitBake. Regard, Jörg
diff --git a/doc/bitbake-user-manual/bitbake-user-manual-execution.rst b/doc/bitbake-user-manual/bitbake-user-manual-execution.rst index 0e20d5933..99b91ba50 100644 --- a/doc/bitbake-user-manual/bitbake-user-manual-execution.rst +++ b/doc/bitbake-user-manual/bitbake-user-manual-execution.rst @@ -728,35 +728,29 @@ bitbake, or set it in ``conf/local.conf``:: BB_LOGCONFIG = "hashequiv.json" -Another example is this ``warn.json`` file to log all ``WARNING`` and +Another example is this ``warn.yaml`` file to log all ``WARNING`` and higher priority messages to a ``warn.log`` file:: - { - "version": 1, - "formatters": { - "warnlogFormatter": { - "()": "bb.msg.BBLogFormatter", - "format": "%(levelname)s: %(message)s" - } - }, + version: 1 - "handlers": { - "warnlog": { - "class": "logging.FileHandler", - "formatter": "warnlogFormatter", - "level": "WARNING", - "filename": "warn.log" - } - }, + '@disable_existing_loggers': false - "loggers": { - "BitBake": { - "handlers": ["warnlog"] - } - }, + formatters: + warnlogFormatter: + '()': bb.msg.BBLogFormatter + format: '%(levelname)s: %(message)s' - "@disable_existing_loggers": false - } + handlers: + warnlog: + class: logging.FileHandler + formatter: warnlogFormatter + level: WARNING + filename: warn.log + + loggers: + BitBake: + handlers: + - warnlog Note that BitBake's helper classes for structured logging are implemented in ``lib/bb/msg.py``.