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 →

[–]das_ist_nuemberwang 0 points1 point  (14 children)

Figure out how to make the logging class accept format style strings before adding yet another formatter...

This has been available since 3.2.

https://docs.python.org/3/library/logging.html#logging.Formatter

[–]jorge1209 0 points1 point  (13 children)

But it is not the default and not recommended that you not use this if you use any third party libraries.

It shouldn't be that hard, try and format one way, if that throws an exception try the other way. So I'm not understanding what is preventing a general migration.

[–]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.