Thanks Kyle for the feedback :-)
Unfortunately, there is no logging.loglevel attribute.
At the moment, the only way of doing this is modifying the program, parsing input parameters and setting up the logging system.
If you want it only temporarily for debugging purposes, or permanently for all scripts in your system, it's not really feasible.
Think of -Wdefault. You can change settings in the warnings module and modify files each time you wish to enable all warnings. But then again, why would you?
We have debugging flags for warnings, faulthandlers, asyncio etc... Logging I would say is the most important and trivial of all, yet we don't have a flag for it.
On Thu, Feb 20, 2020, 4:24 AM Kyle Stanley firstname.lastname@example.org wrote:
This can already be done from the command line through --log=LEVEL,
which sets the logging.loglevel attribute. In the how-to section of the docs, this is demonstrated in the following example:
Note: "loglevel" is an arbitrary name, but this can be implemented trivially with something like argparse to check for a --log argument.
On Wed, Feb 19, 2020 at 9:19 PM Kyle Stanley email@example.com wrote:
Setting PYTHONLOGGING to any log level or level name will initialize
logging.basicConfig() with that appropriate level.
This can already be done from the command line through --log=LEVEL, which sets the logging.loglevel attribute. In the how-to section of the docs, this is demonstrated in the following example:
# assuming loglevel is bound to the string value obtained from the# command line argument. Convert to upper case to allow the user to# specify --log=DEBUG or --log=debugnumeric_level = getattr(logging, loglevel.upper(), None)if not isinstance(numeric_level, int): raise ValueError('Invalid log level: %s' % loglevel)logging.basicConfig(level=numeric_level, ...)
Is there a practical reason why the above doesn't work for you? Otherwise, I see no reason to add a new environment variable that effectively does the same thing.
On Wed, Feb 19, 2020 at 8:16 PM Bar Harel firstname.lastname@example.org wrote:
Another idea I've had that may be of use:
PYTHONLOGGING environment variable.
Setting PYTHONLOGGING to any log level or level name will initialize logging.basicConfig() with that appropriate level.
Another option would be that -x dev or a different -x logging will initialize basic config.
Will be useful mostly for debugging purposes instead of temporarily modifying the code.
Kinda surprised it doesn't exist tbh.
Bar Harel _______________________________________________ Python-ideas mailing list -- email@example.com To unsubscribe send an email to firstname.lastname@example.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://email@example.com/message/I74LVJ... Code of Conduct: http://python.org/psf/codeofconduct/