journalwatch bug: bytes-like objects
Closed this issue · 2 comments
Greetings!
I've been using journalwatch for quite a while and haven't had any issues until I recently installed mpd (Music Player Daemon).
It's quite chatty by default in Arch Linux and sometimes it outputs data that journalctl considers binary in nature; which it masks as "blob data".
However this type of log data causes journalwatch (0.2.2) to crash with a (seemingly) unhelpful stack trace.
I've created a patch that fixes the issue by emulating journalctl's behavior. Further below is more details regarding the patch and the problem at hand.
Patch: https://gist.github.com/hdak1945git/1943dcf77a5534e865fde591b9939955
When journalwatch (0.2.2) encounters lines marked as "binary" it throws an exception when filtering:
Traceback (most recent call last):
File "/usr/bin/journalwatch", line 22, in <module>
sys.exit(journalwatch.main())
File "/usr/lib/python3.5/site-packages/journalwatch.py", line 466, in main
run()
File "/usr/lib/python3.5/site-packages/journalwatch.py", line 453, in run
if not filter_message(patterns, entry):
File "/usr/lib/python3.5/site-packages/journalwatch.py", line 310, in filter_message
if filt.match(entry['MESSAGE']):
TypeError: cannot use a string pattern on a bytes-like object
Skimming through the system log with a plain journalctl
results in various lines with text similar to [66B blob data]
. Running journalctl -a
shows what I'm assuming to be malformed UTF8 -- mpd was specifically complaining about ID3 tags for a few certain Japanese songs.
The patch works against these lines in journalwatch.py:
- line:282 in format_entry:
words.append(entry.get('MESSAGE', 'EMPTY!'))
- line:310 in filter_messsage:
if filt.match(entry['MESSAGE']):
With a function wrapping around entry.get
, replacing bytes-typed data (when specified) with a formatted string similar to:
[journalwatch: {data_length}B blob data]
Thanks! The patch looks good apart from some style issues - I'll apply it later today.
This was a loooong "later today" - sorry for that, I somehow completely forgot about journalwatch again 😆