On Sat, Jun 6, 2020 at 6: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


I was also under the impression that a new thread had been started, since
that's what it looks like in my inbox, but everything is actually under
that link already. Mailman is confusing.


> 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?
>

I'm assuming you made a small mistake here, because `PYTHONLOGGING` would
take a log level, not a filename.


> 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?
>

My understanding is that it does something like:

```
import logging
import os

logging.basicConfig(level=os.environ["PYTHONLOGGING"])
```

and that this is useful if you're using a library that uses logging, i.e. `
logging.info(...)` calls have already been written for you, you just want
an easy way to activate them.

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?
>

I think for users familiar with environment variables, `PYTHONLOGGING=INFO
python myscript.py` might be easier to remember than `import
logging; logging.basicConfig(level='INFO')`. On the other hand, the Python
code is fairly discoverable in an IDE. `import log` autocompletes `logging`
for me, `logging.config` autocompletes `logging.basicConfig`, and from
there it's easy to see the docstring and parameters. And adding more ways
of doing things can make learning harder.


> 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.
>

I think this last point is interesting, and puts me in favour of explicit
calls to basicConfig overriding the environment variable, so the
environment variable wouldn't be *exactly* equivalent to a call to
basicConfig.
_______________________________________________
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/QZFE4EYRBPIBSDNBE4ARNTU7EPES3B3P/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to