Logging issues
q-wertz opened this issue ยท 6 comments
Not sure if I understand the logging library wrong ๐ .
The problem is, that when importing the traffic library I get logging messages twice. This is due to how the logging library is used in this library. By using e.g. logger = logging.getLogger()
, logging.info(f"expire aircraft {icao}", โฆ)
a StreamHandler is implicitely added to the root logger and as all other loggers are children of the root logger, this StreamHandler will output everything to console.
When I remove the implicitly added Handler after importing traffic.core
everything works as expected...
As I understand it, it would be better to generate a children logger in this library (logger = logging.getLogger("traffic")
) where all the log messages of the library are logged to and which can then be turned on/off by the programmer who is importing traffic
.
A good explanation is given in https://stackoverflow.com/a/35326281 I think.
Please follow these steps to make it more efficient to solve your issue:
- Search for duplicate issues.
- Use the latest version of traffic, ideally the HEAD of the github, and activate the
DEBUG
logging level. - Describe how to reproduce the bug and include the full code and data to reproduce it, ideally using a sample trajectory from the library. Sample trajectories are extensively used in the tests suite.
- Limit the output of your exceptions to what is strictly necessary.
You may activate the DEBUG
level with the following snippet:
import logging
logging.basicConfig(level=logging.DEBUG)
Thank you for the link. I must say I encountered similar unclear behaviour last week with the logging module.
I will read your link and try to make sense of it.
In the meantime, don't hesitate to open a PR if you have a clear idea of what to fix.
Just saw you also use tqdm. There for me also issues appeared due to the SteamHandler.
I give it a shot. Might take some time and I'm also no expert in the logging library as I have to admit ๐
Hi @q-wertz could you please clarify when you encounter this issue?
Is it while importing the library or while running an application?
(This logging line you mention is in traffic/console/decode.py
if I am not mistaken...)
In my case it was when running in my own application. I just wanted to add it as a note for someone stumbling into the same issues.
I created a custom logging handler (in parallel to https://github.com/tqdm/tqdm/blob/4f208e72552c4d916aa4fe6a955349ee8b2ed353/tqdm/contrib/logging.py#L18-L34) which does not directly write to console but uses the tqdm write function. Thus the log messages appear above the progress bar.
Due to the added handler from traffic
it messes this behavior up.
ok, but then if you are with your own application, I don't really get where the faulty line in the library is... ๐
It seems to me that the only handler added from traffic is at the application level, not at the library level.
The handler is added as soon as traffic.core
is imported... You can see it before and after the import in the logging.root.handlers
list.
I am just preparing a pull request, you can take a look in a second ๐