Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly flush when writing access log entries #520

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cjwatson
Copy link

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.
Copy link
Member

@carltongibson carltongibson left a comment

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
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
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
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
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
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.

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