[Python-Dev] transitioning from % to {} formatting
Vinay Sajip
vinay_sajip at yahoo.co.uk
Thu Oct 1 08:15:35 CEST 2009
Antoine Pitrou <solipsis <at> pitrou.net> writes:
> Why not allow logging.Formatter to take a callable, which would in turn call
> the callable with keyword arguments?
>
> Therefore, you could write:
> logging.Formatter("{asctime} - {name} - {level} - {msg}".format)
>
> and then:
> logging.critical(name="Python", msg="Buildbots are down")
This seems perhaps usable for a Formatter instantiation (infrequent) but a
problem for the case where you want to convert format_str + args -> message
(potentially frequent, and less readable). Another problem is that logging
calls already use keyword arguments (extra, exc_info) and so backward
compatibility might be compromised. It also feels like passing a callable could
encourage patterns of usage which restrict our flexibility for future changes:
we want for now to just allow choosing between % and {}, but a callable can do
anything. That's more flexible, to be sure, but more specialized formatting
requirements are already catered for using e.g. the PercentMessage/BraceMessage
approach.
Regards,
Vinay Sajip
More information about the Python-Dev
mailing list