The basics of the logging module mystify me

Skip Montanaro skip.montanaro at gmail.com
Fri Apr 20 11:50:52 EDT 2018


> I've no idea what setting log.level does; I would normally use
> logging.basicConfig to set that sort of thing.
>
> logging.basicConfig(level=logging.INFO)

The log.level setting is what calling log.setLevel(...) does under the
covers. What neither apparently do is have any effect on whatever
handlers exist (thank you Thomas Jollans for the clue on the handler
of last resort).

Now that I know, perhaps I can begin to use it more effectively. It
still seems to me like there are at least one too many calls necessary
to have a working logger. In simple systems logging should basically
be no more difficult to use than print statements. Create a logger and
go. No configuration should be required. I understand that the call to
basicConfig() isn't too difficult, but its name does not suggest that
it performs any actions. It is also a bit surprising to me that its
names didn't go through a PEP8 purification step for Python 3.x.

I thought basicConfig wasn't always present, but looking back in time,
I see it was there in Guido's initial commit (Nov 13, 2002, I think,
for 2.3a1). Looking at git blame output for the docs I saw my name. I
checked in the (rough) initial version of the docs the next day
(followed quickly by LaTeX markup cleanup by several other devs). I
have absolutely no recollection of that activity. Lotta water under
the mental bridge since then.

Paul Moore mentioned logbook. I'll take a look at that when I have a
moment. I have played with Eliot (https://eliot.readthedocs.io/) a
bit. Even if it doesn't suit you, I think it's a worthwhile read to
consider other ways to think about logging.

Skip



More information about the Python-list mailing list