Fix logging in the server for py3

This commit is contained in:
Kovid Goyal 2019-12-05 10:19:38 +05:30
parent f884aa1307
commit 9f57d6ce52
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -12,6 +12,7 @@ from operator import itemgetter
from calibre import prints from calibre import prints
from calibre.constants import iswindows from calibre.constants import iswindows
from calibre.utils.terminal import polyglot_write
from calibre.srv.errors import HTTPNotFound from calibre.srv.errors import HTTPNotFound
from calibre.utils.localization import get_translator from calibre.utils.localization import get_translator
from calibre.utils.socket_inheritance import set_socket_inherit from calibre.utils.socket_inheritance import set_socket_inherit
@ -327,9 +328,16 @@ class RotatingStream(object):
def flush(self): def flush(self):
self.stream.flush() self.stream.flush()
def write(self, x):
return polyglot_write(self.stream, True, 'utf-8', x)
def prints(self, level, *args, **kwargs): def prints(self, level, *args, **kwargs):
kwargs['file'] = self.stream kwargs['file'] = self
self.current_pos += prints(*args, **kwargs) prints(*args, **kwargs)
try:
self.current_pos = self.stream.tell()
except EnvironmentError:
self.current_pos = 0
# line bufferring only works with text mode streams # line bufferring only works with text mode streams
end = kwargs.get('end', b'\n') end = kwargs.get('end', b'\n')
if isinstance(end, unicode_type): if isinstance(end, unicode_type):