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 <aeros167@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 <bzvi7919@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-leave@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/I74LVJ... Code of Conduct: http://python.org/psf/codeofconduct/