mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-01 16:11:18 +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:
parent
cf399da8d7
commit
80976c8cf5
@ -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
|
command-line argument and `.bat` file for users to enable it. It cannot be
|
||||||
selected from Settings in the UI.
|
selected from Settings in the UI.
|
||||||
|
|
||||||
As well as just using bare `logger.trace(...)` you can also gate it to only
|
**Do not use a bare `logger.trace(...)` call** unless you're 100% certain
|
||||||
log if asked to at invocation time by utilising the `--trace-on ...`
|
it's only temporary **and will be removed before any code merge**. In
|
||||||
command-line argument. e.g.
|
that case you would utilise `EDMarketConnector.py --trace` to see the output.
|
||||||
`EDMarketConnector.py --trace --trace-on edsm-cmdr-events`. Note how you
|
|
||||||
still need to include `--trace`.
|
|
||||||
|
|
||||||
`--trace-on` stores its arguments in `config.trace_on`.
|
Instead, you should gate any TRACE logging using the `trace_if()` helper
|
||||||
To make use of `--trace-on`, you can either check `config.trace_on` yourself:
|
method provided on `logger`:
|
||||||
|
|
||||||
```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
|
```python
|
||||||
logger.trace_if('my-trace-rule', 'my-log-message')
|
logger.trace_if('my-trace-rule', 'my-log-message')
|
||||||
```
|
```
|
||||||
|
|
||||||
This way you can set up TRACE logging that won't spam just because `--trace` is used.
|
This would then be triggered by running EDMarketConnector with the
|
||||||
|
appropriate command-line arguments:
|
||||||
|
|
||||||
|
EDMarketConnector.py --trace-on my-trace-rule
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -130,10 +130,10 @@ if __name__ == '__main__': # noqa: C901
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
level_to_set: Optional[int] = None
|
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
|
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
|
level_to_set = logging.TRACE_ALL # type: ignore # it exists
|
||||||
|
|
||||||
if level_to_set is not None:
|
if level_to_set is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user