Opened 7 years ago

Closed 5 years ago

#29329 closed Cleanup/optimization (fixed)

Inconsistent datetime logging from runserver.

Reported by: Sjoerd Job Postmus Owned by: Hasan Ramezani
Component: Core (Other) Version: 2.0
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In Django 1.11 and higher, the runserver logging can sometimes be inconsistent.

[16/Apr/2018 13:32:35] "GET /some/local/url HTTP/1.1" 200 7927
[2018-04-16 13:32:35,745] - Broken pipe from ('127.0.0.1', 57570)

This is because logging from WSGIRequestHandler uses server_time as calculated using BaseHTTPServer.log_date_time_string. On the other hand, WSGIServer uses logging without providing a server_time. This gets "fixed" in ServerFormatter.format using self.formatTime(record, self.datefmt), which uses a completely different format.

Currently we make this at least consistent by providing the datefmt parameter when constructing the logger, but it would be better if they were coded to be in sync (and configurable?).

(Looking into it further, it looks like we should be using %(asctime)s instead of %(server_time)s, but would be good if that were the suggested default. In https://docs.djangoproject.com/en/2.0/releases/1.10/#runserver-output-goes-through-logging we see %(server_time)s.)

Change History (6)

comment:1 by Tim Graham, 7 years ago

Component: UncategorizedCore (Other)
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

comment:2 by Srinivas Reddy Thatiparthy, 7 years ago

Owner: changed from nobody to Srinivas Reddy Thatiparthy
Status: newassigned

comment:3 by Hasan Ramezani, 5 years ago

Has patch: set
Owner: changed from Srinivas Reddy Thatiparthy to Hasan Ramezani
Last edited 5 years ago by Mark (previous) (diff)

comment:4 by Carlton Gibson, 5 years ago

Patch needs improvement: set

comment:5 by Hasan Ramezani, 5 years ago

Patch needs improvement: unset

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 7b31ba54:

Fixed #29329 -- Made datetime logging from runserver more consistent.

Setting default_msec_format=None will make it the same, unfortunately
it's not supported by Python, see https://bugs.python.org/issue40300.

Note: See TracTickets for help on using tickets.
Back to Top