From 80976c8cf5970ae858dd245992e094b18b44e83f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 13 Aug 2021 11:55:10 +0100 Subject: [PATCH] TRACE: Don't require `--trace` with other trace options * `--trace-on ...` no longer requires `--trace` as well. * Corrected check for `--trace-on *|all`. * Updated Contributing.md to reflect mandated use of `logger.trace_if(...)`, with bare `logger.trace(...)` only for on the fly, code not going to be merged, use. --- Contributing.md | 30 ++++++++++++++---------------- EDMarketConnector.py | 4 ++-- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Contributing.md b/Contributing.md index 54e39907..814ff7ca 100644 --- a/Contributing.md +++ b/Contributing.md @@ -408,28 +408,26 @@ In addition to that we utilise one of the user-defined levels as: command-line argument and `.bat` file for users to enable it. It cannot be 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 ...` - command-line argument. e.g. - `EDMarketConnector.py --trace --trace-on edsm-cmdr-events`. Note how you - still need to include `--trace`. + **Do not use a bare `logger.trace(...)` call** unless you're 100% certain + it's only temporary **and will be removed before any code merge**. In + that case you would utilise `EDMarketConnector.py --trace` to see the output. - `--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`: + Instead, you should gate any TRACE logging using the `trace_if()` helper + method provided on `logger`: ```python logger.trace_if('my-trace-rule', 'my-log-message') ``` + + This would then be triggered by running EDMarketConnector with the + appropriate command-line arguments: + + EDMarketConnector.py --trace-on my-trace-rule - This way you can set up TRACE logging that won't spam just because `--trace` is used. + Note that you do **not** also need to specify `--trace`, that's implied. + + This way you can set up TRACE logging that won't spam just because `--trace` + is used. --- diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 5eadd34d..a64fad7b 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -130,10 +130,10 @@ if __name__ == '__main__': # noqa: C901 args = parser.parse_args() level_to_set: Optional[int] = None - if args.trace: + if args.trace or args.trace_on: level_to_set = logging.TRACE # type: ignore # it exists - if args.trace_all or '*' in args.trace_on or 'all' in args.trace_on: + if args.trace_all or (args.trace_on and ('*' in args.trace_on or 'all' in args.trace_on)): level_to_set = logging.TRACE_ALL # type: ignore # it exists if level_to_set is not None: