On Sat, Jun 06, 2020 at 09:31:36PM +0300, Bar Harel wrote:
It's one thing to say that the interpreter takes care of importing logging and setting up a basic logger, and that's great, but I still have to import logging and call the `logging.info(...)` functions, so what does this proposal give us, *in detail* please, and how do I use it?
You would be able to easily see the logs already generated by libraries, without needing to ever modify the Python files.
But if the libraries are already doing logging, can't I already do that? And if the libraries aren't doing logging, this won't magically add logging to them, will it? I think I need to see a (simplified!) but practical example of how this would work, from both the point of view of the library creator, and the library user. Thanks, -- Steven
But if the libraries are already doing logging, can't I already do that?
And if the libraries aren't doing logging, this won't magically add logging to them, will it?
As a best practice, libraries log into a NullHandler to avoid setting up the root logger, and to prevent sending messages to the default fallback. In other words, the current best practice mentioned by the Python docs (which I personally believe is good) prevents you from seeing errors if the root logger wasn't set up correctly, or set up at all. Even if they don't send it to NullHandler, log messages below warning level aren't displayed by default. With my proposal you'd be able to see everything with 1 simple flag, no matter the configuration. It could have saved me, and probably other developers as well, lots of time. Regarding your request for an example, this won't change anything from the point of view of the library creator. As for the library user, he can continue as he does, knowing that in case there's ever a hard-to-figure bug he can turn on that flag together with -Xdev and have an easier time figuring things out. It's also useful for external developers tackling code that is not theirs. They can give themselves a guarantee that no matter the script, if it logs, it'll show. Keep in mind developers can also use it for cases where they don't set up the logging, as a permanent replacement for basicConfig, but I believe it's not a best practice for many reasons. Bar
participants (2)
-
Bar Harel
-
Steven D'Aprano