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

Improve handling of newlines in log messages #596

Merged
merged 4 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ of those changes to CLEARTYPE SRL.
| [@DiegoPomares](https://github.com/DiegoPomares/) | Diego Pomares |
| [@pahrohfit](https://github.com/pahrohfit/) | Robert Dailey |
| [@nhairs](https://github.com/nhairs) | Nicholas Hairs |
| [@5tefan](https://github.com/5tefan/) | Stefan Codrescu |
4 changes: 4 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ Fixed

* The ``CurrentMessage`` middleware now works under AsyncIO. (`#586`_,
`#593`_, `@pahrohfit`_)
* Improved logging behavior under different buffer modes. (`#596`_,
`@5tefan`_)

.. _#586: https://github.com/Bogdanp/dramatiq/issues/586
.. _#593: https://github.com/Bogdanp/dramatiq/pull/593
.. _#596: https://github.com/Bogdanp/dramatiq/pull/596
.. _@pahrohfit: https://github.com/pahrohfit
.. _@5tefan: https://github.com/5tefan

Added
^^^^^
Expand Down
11 changes: 2 additions & 9 deletions dramatiq/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,21 +338,14 @@ def watch_logs(log_filename, pipes, stop):
for event in events:
try:
while event.poll():
# StreamHandler writes newlines into the pipe separately
# from the actual log entry; to avoid back-to-back newlines
# in the events pipe (causing multiple entries on a single
# line), discard newline-only data from the pipe
try:
data = event.recv_bytes()
except EOFError:
event.close()
raise

data = data.decode("utf-8", errors="replace").rstrip("\n")
if not data:
continue

log_file.write(data + "\n")
data = data.decode("utf-8", errors="replace")
log_file.write(data)
log_file.flush()
except BrokenPipeError:
event.close()
Expand Down