1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-13 07:47:14 +03:00

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.
This commit is contained in:
Athanasius 2021-08-13 11:55:10 +01:00
parent cf399da8d7
commit 80976c8cf5
No known key found for this signature in database
GPG Key ID: AE3E527847057C7D
2 changed files with 16 additions and 18 deletions

View File

@ -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.
---

View File

@ -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: