Skip to content

Explicitly flush when writing access log entries#520

Closed
cjwatson wants to merge 1 commit into
django:mainfrom
cjwatson:access-log-stdout-flush
Closed

Explicitly flush when writing access log entries#520
cjwatson wants to merge 1 commit into
django:mainfrom
cjwatson:access-log-stdout-flush

Conversation

@cjwatson

Copy link
Copy Markdown

daphne 1.0.0 arranged to flush access logs immediately (#53, #54), but only when logging to a file. It's often convenient to log to stdout instead and rely on the systemd journal, but at the moment that results in access logs being unhelpfully block-buffered. Explicitly flush entries so that this works regardless of the logging destination.

daphne 1.0.0 arranged to flush access logs immediately (django#53, django#54), but
only when logging to a file.  It's often convenient to log to stdout
instead and rely on the systemd journal, but at the moment that results
in access logs being unhelpfully block-buffered.  Explicitly flush
entries so that this works regardless of the logging destination.

@carltongibson carltongibson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cjwatson Thanks for this.

I'm a little reluctant to just change such a long-standing behaviour. 🤔

Q: why not just run with PYTHONUNBUFFERED in this case?

@cjwatson

Copy link
Copy Markdown
Author

That's a workaround I may indeed end up using (though it's not especially urgent for us), but it seems like a less economical change.

@carltongibson

Copy link
Copy Markdown
Member

Using existing features, and keeping the behaviour of stdout in line with Python defaults seems the more economical solution to me 🤔

@cjwatson

Copy link
Copy Markdown
Author

Depends on your point of view, I guess. Another approach to this would be #473, since Python's logging module normally flushes the output stream if it can.

@cjwatson

Copy link
Copy Markdown
Author

The main reason I don't love PYTHONUNBUFFERED is that unbuffered is not the same as line-buffered, and I worry that it might cause lines of output (or indeed error output, since PYTHONUNBUFFERED affects stderr too) to end up being interleaved in some cases where any kind of multi-threading is involved.

@carltongibson

Copy link
Copy Markdown
Member

Yes #473 would be the way to go.

If you'd like to offer a review there, we can try and get that in.

@carltongibson

Copy link
Copy Markdown
Member

I'll close in favour of #473.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants