Force logging utf8
This commit is contained in:
1 parent
c9638ec3fa
commit
d4f2f12924
5 files changed
+26
-15
No files matched your search
@@ -47,6 +47,17 @@ def toUnicode(original, *args):
|
||||
ascii_text = str(original).encode('string_escape')
|
||||
return toUnicode(ascii_text)
|
||||
|
||||
def toUTF8(original):
|
||||
try:
|
||||
if isinstance(original, str) and len(original) > 0:
|
||||
# Try to detect
|
||||
detected = detect(original)
|
||||
return original.decode(detected.get('encoding')).encode('utf-8')
|
||||
else:
|
||||
return original
|
||||
except:
|
||||
#log.error('Failed encoding to UTF8: %s', traceback.format_exc())
|
||||
raise
|
||||
|
||||
def ss(original, *args):
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import re
|
||||
import traceback
|
||||
|
||||
|
||||
class CPLog(object):
|
||||
@@ -54,19 +55,19 @@ class CPLog(object):
|
||||
|
||||
def safeMessage(self, msg, replace_tuple = ()):
|
||||
|
||||
from couchpotato.core.helpers.encoding import ss, toUnicode
|
||||
from couchpotato.core.helpers.encoding import ss, toUTF8
|
||||
|
||||
msg = ss(msg)
|
||||
msg = toUTF8(msg)
|
||||
|
||||
try:
|
||||
if isinstance(replace_tuple, tuple):
|
||||
msg = msg % tuple([ss(x) if not isinstance(x, (int, float)) else x for x in list(replace_tuple)])
|
||||
msg = msg % tuple([toUTF8(x) for x in list(replace_tuple)])
|
||||
elif isinstance(replace_tuple, dict):
|
||||
msg = msg % dict((k, ss(v)) for k, v in replace_tuple.iteritems())
|
||||
msg = msg % dict((k, toUTF8(v)) for k, v in replace_tuple.iteritems())
|
||||
else:
|
||||
msg = msg % ss(replace_tuple)
|
||||
except Exception as e:
|
||||
self.logger.error('Failed encoding stuff to log "%s": %s' % (msg, e))
|
||||
msg = msg % toUTF8(replace_tuple)
|
||||
except:
|
||||
self.logger.error('Failed encoding stuff to log "%s": %s' % (msg, traceback.format_exc()))
|
||||
|
||||
self.setup()
|
||||
if not self.is_develop:
|
||||
@@ -83,4 +84,4 @@ class CPLog(object):
|
||||
except:
|
||||
pass
|
||||
|
||||
return toUnicode(msg)
|
||||
return toUTF8(msg)
|
||||
@@ -1,9 +1,9 @@
|
||||
import codecs
|
||||
import os
|
||||
import re
|
||||
import traceback
|
||||
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.helpers.encoding import toUnicode
|
||||
from couchpotato.core.helpers.variable import tryInt, splitString
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
@@ -103,9 +103,8 @@ class Logging(Plugin):
|
||||
if not os.path.isfile(path):
|
||||
break
|
||||
|
||||
f = open(path, 'r')
|
||||
log_content = toUnicode(f.read())
|
||||
raw_lines = self.toList(log_content)
|
||||
f = codecs.open(path, 'r', 'utf-8')
|
||||
raw_lines = self.toList(f.read())
|
||||
raw_lines.reverse()
|
||||
|
||||
brk = False
|
||||
@@ -131,7 +130,7 @@ class Logging(Plugin):
|
||||
|
||||
def toList(self, log_content = ''):
|
||||
|
||||
logs_raw = toUnicode(log_content).split('[0m\n')
|
||||
logs_raw = log_content.split('[0m\n')
|
||||
|
||||
logs = []
|
||||
for log_line in logs_raw:
|
||||
|
||||
Reference in new issue
Block a user