From 53bc4c57d7c5df2f1646b80febe5ef489b4720e3 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 30 Jul 2024 12:10:04 +0100 Subject: [PATCH] Explicitly flush when writing access log entries 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/access.py | 1 + daphne/cli.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/daphne/access.py b/daphne/access.py index e18138a..2cd605d 100644 --- a/daphne/access.py +++ b/daphne/access.py @@ -68,3 +68,4 @@ class AccessLogGenerator: length or "-", ) ) + self.stream.flush() diff --git a/daphne/cli.py b/daphne/cli.py index a036821..05fb48f 100755 --- a/daphne/cli.py +++ b/daphne/cli.py @@ -224,7 +224,7 @@ class CommandLineInterface: if args.access_log == "-": access_log_stream = sys.stdout else: - access_log_stream = open(args.access_log, "a", 1) + access_log_stream = open(args.access_log, "a") elif args.verbosity >= 1: access_log_stream = sys.stdout