@cryptotaxi247 / netdata-1 / commits / c649de8e6

fix #5430 - LogService._get_raw_data under python3 fails on undecodable data (#5431)

* Fix LogService._get_raw_data under python3 * Move python version check to init * Mark open_args as private

Adam Pardyl committed Feb 20, 2019 at 08:13 UTC c649de8e68229cdda83ea4ff33a080250b1e5497
1 file changed +3 -1
collectors/python.d.plugin/python_modules/bases/FrameworkServices/LogService.py
+3 -1
@@ -5,6 +5,7 @@
5 # SPDX-License-Identifier: GPL-3.0-or-later
6
7 from glob import glob
8 +import sys
9 import os
10
11 from bases.FrameworkServices.SimpleService import SimpleService
@@ -17,6 +18,7 @@ class LogService(SimpleService):
18 self.__glob_path = self.log_path
19 self._last_position = 0
20 self.__re_find = dict(current=0, run=0, maximum=60)
21 + self.__open_args = {'errors': 'replace'} if sys.version_info[0] > 2 else {}
22
23 def _get_raw_data(self):
24 """
@@ -34,7 +36,7 @@ class LogService(SimpleService):
36 elif size < self._last_position:
37 self._last_position = 0 # read from beginning if file has shrunk
38
37 - with open(self.log_path) as fp:
39 + with open(self.log_path, **self.__open_args) as fp:
40 fp.seek(self._last_position)
41 for line in fp:
42 lines.append(line)