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 <aeros...@gmail.com> 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 <aeros...@gmail.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, ...)
>>
>> (https://docs.python.org/3/howto/logging.html#logging-to-a-file)
>>
>> 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 <bzvi7...@gmail.com> 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 -- python-ideas@python.org
>>> To unsubscribe send an email to python-ideas-le...@python.org
>>> https://mail.python.org/mailman3/lists/python-ideas.python.org/
>>> Message archived at
>>> https://mail.python.org/archives/list/python-ideas@python.org/message/I74LVJWJLE2LUCCZGOF5A5JDSDHJ6WX2/
>>> Code of Conduct: http://python.org/psf/codeofconduct/
>>>
>>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/I6SJKDONKSUTATL4QBJMR5Z3YZTKI6TC/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to