[Python-Dev] Change to logging Formatters: support for alternative format styles (original) (raw)
Barry Warsaw barry at python.org
Fri Oct 29 17:07:02 CEST 2010
- Previous message: [Python-Dev] Change to logging Formatters: support for alternative format styles
- Next message: [Python-Dev] Change to logging Formatters: support for alternative format styles
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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>
- Previous message: [Python-Dev] Change to logging Formatters: support for alternative format styles
- Next message: [Python-Dev] Change to logging Formatters: support for alternative format styles
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]