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.
This commit is contained in:
Colin Watson 2024-07-30 12:10:04 +01:00
parent 4a55faca45
commit 53bc4c57d7
2 changed files with 2 additions and 1 deletions

View File

@ -68,3 +68,4 @@ class AccessLogGenerator:
length or "-", length or "-",
) )
) )
self.stream.flush()

View File

@ -224,7 +224,7 @@ class CommandLineInterface:
if args.access_log == "-": if args.access_log == "-":
access_log_stream = sys.stdout access_log_stream = sys.stdout
else: else:
access_log_stream = open(args.access_log, "a", 1) access_log_stream = open(args.access_log, "a")
elif args.verbosity >= 1: elif args.verbosity >= 1:
access_log_stream = sys.stdout access_log_stream = sys.stdout