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

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to