Skip to content

Commit d3ddb49

Browse files
committed
Don't crash on a string decoding exception
1 parent 4919ae7 commit d3ddb49

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ When using ``copytruncate`` style log rotation, two race conditions can occur:
466466
watch which may be truncated are generally going to be large enough
467467
and slow-filling enough that this won't crop up in the wild.
468468

469+
----
470+
469471
When you get an error similar to ``ImportError: No module named
470472
_sqlite3`` your python seems to miss the sqlite3-module. This can be the
471473
case on FreeBSD and probably other systems. If so, use the local package
@@ -474,6 +476,13 @@ manager or port system to build that module. On FreeBSD::
474476
cd /usr/ports/databases/py-sqlite3
475477
sudo make install clean
476478

479+
----
480+
481+
Binary data in your logs will be converted to escape sequences or ?'s depending on the encoding settings to prevent decoding exceptions from crashing beaver.
482+
483+
| http://docs.python.org/2/library/codecs.html#codecs.replace_errors
484+
| malformed data is replaced with a suitable replacement character such as '?' in bytestrings and '\ufffd' in Unicode strings.
485+
477486
Credits
478487
=======
479488

beaver/worker/tail.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ def open(self, encoding=None):
8282
_file = gzip.open(self._filename, 'rb')
8383
else:
8484
if encoding:
85-
_file = io.open(self._filename, 'r', encoding=encoding)
85+
_file = io.open(self._filename, 'r', encoding=encoding, errors='replace')
8686
elif self._encoding:
87-
_file = io.open(self._filename, 'r', encoding=self._encoding)
87+
_file = io.open(self._filename, 'r', encoding=self._encoding, errors='replace')
8888
else:
89-
_file = io.open(self._filename, 'r')
89+
_file = io.open(self._filename, 'r', errors='replace')
9090
except IOError, e:
9191
self._log_warning(str(e))
9292
_file = None

beaver/worker/worker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,11 @@ def open(self, filename, encoding=None):
582582
else:
583583
file_encoding = self._beaver_config.get_field('encoding', filename)
584584
if encoding:
585-
_file = io.open(filename, "r", encoding=encoding)
585+
_file = io.open(filename, "r", encoding=encoding, errors='replace')
586586
elif file_encoding:
587-
_file = io.open(filename, "r", encoding=file_encoding)
587+
_file = io.open(filename, "r", encoding=file_encoding, errors='replace')
588588
else:
589-
_file = io.open(filename, "r")
589+
_file = io.open(filename, "r", errors='replace')
590590
except IOError, e:
591591
self._logger.warning(str(e))
592592
_file = None

0 commit comments

Comments
 (0)