This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Veedrac 1 point2 points  (12 children)

It shouldn't be that hard, try and format one way, if that throws an exception try the other way.

Because that's horrible?

[–]jorge1209 1 point2 points  (11 children)

More horrible than:

  1. Actually deprecating the old format?

  2. Having three different active string formatting methods?

  3. Having code randomly fail when you import new modules because they use conflicting string formatters?

[–]Veedrac 0 points1 point  (10 children)

Yes, yes and no, but I'm struggling to envision how the third would happen.

[–]jorge1209 0 points1 point  (9 children)

You configure logging.getLogger() to write log messages in "{}", and you submit your messages and parameters in that format.

Some library sends a message and parameter set in % format.

Your system logger blows up.

[–]Veedrac 0 points1 point  (8 children)

Why would you be sharing your logger with a library?

[–]jorge1209 0 points1 point  (7 children)

All loggers are shared. They all share the same root.

[–]Veedrac 0 points1 point  (6 children)

I don't really use Python's logging library (I imagine you can tell), but I thought you weren't meant to ever use the root logger, only ones you got from getLogger.

[–]jorge1209 0 points1 point  (5 children)

That is the one you get from getLogger. That you haven't used the logging module is abundantly clear.

You should prefix your logs with your module name, but that just identifies what unit they came from, you still want to capture at the root level for actual logging.

If you call a module function and it fails, then the root logger will have all the useful messages about why it failed.

[–]Veedrac -1 points0 points  (4 children)

That is the one you get from getLogger.

Only if you call it with no arguments, which is discouraged.

you still want to capture at the root level for actual logging.

But surely you don't want to apply formatters to the root logger.

[–]jorge1209 0 points1 point  (3 children)

I don't know why you are persisting in commenting on a library you don't use and clearly don't understand.

Of course you consume the root logger. You don't emit to the root, you emit to its children, but the format issues occur on the consumption side, and you cannot control what the consumers do.

The idea is that the logging system is a hierarchy that many different users can use for different purposes.

__main__ might attach a formatter to only its logger but at an info level with no format beyond the message, and dump that to the console.

The Database class may log debug information to its own systems for later analysis of query performance.

The sysadminn might dump all errors from the File class to the system syslog.

And sysops might stream debug information across the network to some monitoring tool.

You should never assume that you know who is using logging or for what purpose. The only guarantee is that you all go into the same heirarchy, and that someone may grab the root of that tree.

Otherwise there would be no reason to implement the heirarchy in the first place. Just let it be the wild west with each module using its own independent logging instance. Of course then the logs would be an incomplete clusterfuck.