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.

It's much like -Xdev, -Wdefault etc.


How is this going to impact basic and intermediate users of logging?


Without the need of entering logging internals, you would be able to see
the logs, or be able to easily create a debug environment with the env var,
regardless of the script running underneath.

So what happens if I have a script that explicitly calls basicConfig but
I accidentally run it with the -L switch or PYTHONLOGGING?


It's a good question. Unlike Alex's suggestion, my original point of view
is that it will be exactly like basicConfig.
If someone wrote basicConfig(level=INFO), and you wish to see everything
regardless of current setup (mostly for pinpointing bugs), you'd be able to
set it to DEBUG in an easy way, that will work on all scripts.

E.g. I may have an alias 'python=python -L', or I may have set the
environment variable in a shell and then forgotten it. I sometimes have
shells open for weeks at a time, I'm going to be terribly confused if
myscript logs correctly in one open shell but not in another because of
an environment variable I set two weeks earlier.


 Well, PYTHONPATH, PYTHONWARNINGS and all other env vars will cause the
same issue and confusion.
I think it's up to the developer to know how to set up his own environment.

Keep in mind that all arguments in favor of this, and all arguments
against, also apply to PYTHONWARNINGS.
It's exactly there for when you wish to show suppressed deprecation
warnings on dev environments, or further customize the filter.
Adding this will offer a more consistent API, as there's no reason to make
an actual distinction between the two.
But that's just icing on the cake IMO.

I can give you an elaboration of a few hard-to-debug cases that made me
surprised such a feature does not exist.

Bar Hare

On Sat, Jun 6, 2020, 7:46 AM Steven D'Aprano <st...@pearwood.info> wrote:

> I think the first thing that needs to be done, before creating a bpo
> issue, is to get consensus that it's both a plausible idea and a good
> idea, and I don't think that the discussion did either.
>
> Discussion starts here:
>
>
> https://mail.python.org/archives/list/python-ideas@python.org/thread/I74LVJWJLE2LUCCZGOF5A5JDSDHJ6WX2/#BVUMURTEZFQG36HRCZYRSWJK6OTZIBZG
>
>
> Bar's initial reason for this:
>
> "Will be useful mostly for debugging purposes instead of temporarily
> modifying the code."
>
> Okay, but how does that work? I have a script:
>
>     # myscript.py
>     print("Hello world")
>
> and I want to add logging to it. So I set the environment variable, or
> use the proposed -L command line switch, and call the script:
>
>     PYTHONLOGGING=mylogfile python myscript.py
>
> but what exactly gets logged?
>
> 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?
>
> I've read the entire thread and there is lot of detail there that seems
> to be written for expert users of logging. If you're an expert user of
> logging, you probably don't need an environment variable, or you can
> handle it yourself with os.environ.get('LOGLEVEL').
>
> How is this going to impact basic and intermediate users of logging?
>
> The tutorial warns: "As [logging.basicConfig] is intended as a one-off
> simple configuration facility, only the first call will actually do
> anything: subsequent calls are effectively no-ops."
>
> So what happens if I have a script that explicitly calls basicConfig but
> I accidentally run it with the -L switch or PYTHONLOGGING?
>
> E.g. I may have an alias 'python=python -L', or I may have set the
> environment variable in a shell and then forgotten it. I sometimes have
> shells open for weeks at a time, I'm going to be terribly confused if
> myscript logs correctly in one open shell but not in another because of
> an environment variable I set two weeks earlier.
>
>
>
>
> --
> Steven
> _______________________________________________
> 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/TQM7ZAX5QBB6UHBIKZGWRTBTARERZXIF/
> 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/767PTDG2HT5QU5TUAVSLLWOVYRP3GTUZ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to