[Python-Dev] Change to logging Formatters: support for alternative format styles

Barry Warsaw barry at python.org
Fri Oct 29 17:07:02 CEST 2010


On Oct 25, 2010, at 02:28 PM, Vinay Sajip wrote:

>I've just checked in a change to logging into the py3k branch (r85835),
>including doc changes and tests, for providing slightly more flexibility in
>alternative format styles for logging.
>
>Basically, Formatter.__init__ gets an extra optional keyword arg style=<one of
>'%' (default), '{' or '$'>. This is then used to merge the format string with
>the LogRecord: either fmt % record.__dict__, or fmt.format(**record.dict), or
>string.Template(fmt).substitute(**record.dict). Backward compatibility is
>maintained (unless I've missed something).

This sounds like a reasonable solution that provides the flexibility we want,
while maintaining backward compatibility.  Thanks!

I haven't played with it yet, but do you think it makes sense to add a 'style'
keyword argument to basicConfig()?  That would make it pretty easy to get the
formatting style you want without having to explicitly instantiate a
Formatter, at least for simple logging clients.

Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-dev/attachments/20101029/18e99c7c/attachment.pgp>


More information about the Python-Dev mailing list