django logging - `ServerFormatter.uses_server_time()` forces users to use `{` logging style

69 views
Skip to first unread message

Łukasz Skarżyński

unread,
Feb 7, 2019, 6:34:23 AM2/7/19
to Django developers (Contributions to Django itself)
Hello,

I encountered some troubles with django logging configuration during the update from Django 1.11 to 2.1. This issue was related to this commit and generally `ServerFormatter.uses_server_time()` method.
This method forces users to use `{` logging style, by hard coding it in the following line: `return self._fmt.find('{server_time}') >= 0`, so it works only with `{` style, which is the default one.
I couldn't find any explanation why users should use `{` style instead of `%` or `$` and I think style should be totally irrelevant to Django.
My suggestion is to make `ServerFormatter.uses_server_time()` workable with all logging styles or to add some note to documentation that `{` logging style must be used when `ServerFormatter` is overwritten.
If you decide to make some changes in relation to this issue, I am eager to contribute.

Thank you all for working on Django!

Kind Regards,
Łukasz

Tim Graham

unread,
Feb 8, 2019, 6:11:03 PM2/8/19
to Django developers (Contributions to Django itself)
I'm not opposed to a patch to address your use case.

Łukasz Skarżyński

unread,
Feb 9, 2019, 6:04:44 AM2/9/19
to Django developers (Contributions to Django itself)
Thanks for response.
Should I prepare some PR now?
Generally I think about implementing `.uses_server_time()` using `_style.asctime_search` attribute:

 `self._fmt.find(self._style.asctime_search.replace('asctime', 'server_time')) >=  0`

this call of `str.replace()` can be done even only once in `ServerFormatter.__init__()`.
Reply all
Reply to author
Forward
0 new messages