Indeed, that's why I clarified in the follow-up message; sorry it's been a long day :-).
was simply an arbitrary name chosen for that particular example and
getattr() was used as a way to prefix the module so it would access the
logging level constant instead of the literal name of the level as a
string (which would be invalid to pass to level). You'd likely use
argparse or some other command-line argument parsing utility to get it
in the first place. For example:
parser = argparse.ArgumentParser()
parser.add_argument("--log", dest='logging_level', default='WARNING')
args = parser.parse_args()
numeric_level = getattr(logging, args.logging_level.upper())
(input validation omitted for simplification)
> If you want it only temporarily for debugging purposes, or permanently for all scripts in your system, it's not really feasible.
I'm not sure that I like the idea of overriding the default logging
level being set system-wide, or that there would be an especially strong
use case for it. Instead, it seems more practically common to want to
set it on an individual run of a program temporarily. In such cases,
using some form of command-line parsing utility is a perfectly a viable
> 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.
though, the easier it is to implement on your own, the less of a need
there is to be an environment variable to do it. Also, I think the
logging configuration should be on a per-program basis, rather than
globally (which is what env vars are typically used for).
I'm not opposed to the principle behind the idea, I'm just not
convinced yet that it would be that much better than the options that
are already available, and would be worthwhile to add an entirely new
environment variable for (or be good usage of an env var for that
matter). Perhaps there are other areas to explore for simplifying the
process of changing the logging level from the command-line though.