[Python-Dev] Change to logging Formatters: support for alternative format styles (original) (raw)
Olemis Lang olemis at gmail.com
Fri Oct 29 17:44:03 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 Fri, Oct 29, 2010 at 10:07 AM, Barry Warsaw <barry at python.org> wrote:
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.
Since this may be considered as a little sophisticated, I'd rather
prefer these new classes to be added to configuration sections using
fileConfig (and default behavior if missing), and still leave
basicConfig
unchanged (i.e. basic) .
PS: Good work !
-- Regards,
Olemis.
Blog ES: http://simelo-es.blogspot.com/ Blog EN: http://simelo-en.blogspot.com/
Featured article:
- 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 ]