From 80fbfd17805834b2b8f966171beeafb576a936e5 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 12 Aug 2021 16:46:26 +0200 Subject: [PATCH] Updated docs containing info about trace-if --- Contributing.md | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Contributing.md b/Contributing.md index 02e02b58..54e39907 100644 --- a/Contributing.md +++ b/Contributing.md @@ -409,20 +409,27 @@ In addition to that we utilise one of the user-defined levels as: selected from Settings in the UI. As well as just using bare `logger.trace(...)` you can also gate it to only - log if asked to at invocation time by utilising the `--trace-on ...` + log if asked to at invocation time by utilising the `--trace-on ...` command-line argument. e.g. `EDMarketConnector.py --trace --trace-on edsm-cmdr-events`. Note how you - still need to include `--trace`. The code to check and log would be like: + still need to include `--trace`. + + `--trace-on` stores its arguments in `config.trace_on`. + To make use of `--trace-on`, you can either check `config.trace_on` yourself: + + ```python + import config + if 'my-trace-rule' in config.trace_on: + logger.trace('my log message') + ``` + + or you can use the helper method provided on `logger`: ```python - import config as conf_module # Necessary to see the same config.trace_on as elsewhere + logger.trace_if('my-trace-rule', 'my-log-message') + ``` - if 'edsm-cmdr-events' in conf_module.trace_on: - logger.trace(f'De-queued ({cmdr=}, {entry["event"]=})') - ``` - - This way you can set up TRACE logging that won't spam just because of - `--trace` being used. + This way you can set up TRACE logging that won't spam just because `--trace` is used. ---