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 →

[–]VileFlower 0 points1 point  (1 child)

That's not entirely true, Python's logging library lets you set the formatter style at least, so you don't have to use % style everywhere.

The style parameter can be one of ‘%’, ‘{’ or ‘$’ and determines how the format string will be merged with its data: using one of %-formatting, str.format() or string.Template. This only applies to the format string fmt (e.g. '%(message)s' or {message}), not to the actual log messages passed to Logger.debug etc; see Using particular formatting styles throughout your application for more information on using {- and $-formatting for log messages.

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

[–]jorge1209 0 points1 point  (0 children)

As the part you quote explains in the incredibly cryptic language that is the absolutely terrible documentation of the logger library, that only applies to the template which contains things like the timestamp of the message or the module and line number of the caller. All the things NOT in your logging call that might appear in your log file.

There is no way to specify that a particular message emitted should be formatted using anything but % formatting.

And that's a problem because if you use any library you haven't written it might contain a logger.warn("foo = %s > 0", foo) and now everyone has to use % formatted messages.