Open and write logs and config files in utf-8
This commit is contained in:
parent
b981327df5
commit
391eb27964
2 changed files with 6 additions and 4 deletions
|
@ -337,7 +337,8 @@ class Config(RawConfigParser):
|
||||||
prefix, file = path.split(self.file_name)
|
prefix, file = path.split(self.file_name)
|
||||||
filename = path.join(prefix, '.%s.tmp' % file)
|
filename = path.join(prefix, '.%s.tmp' % file)
|
||||||
fd = os.fdopen(
|
fd = os.fdopen(
|
||||||
os.open(filename, os.O_WRONLY | os.O_CREAT, 0o600), 'w')
|
os.open(filename, os.O_WRONLY | os.O_CREAT, 0o600,), 'w',
|
||||||
|
encoding='utf-8')
|
||||||
for line in lines:
|
for line in lines:
|
||||||
fd.write('%s\n' % line)
|
fd.write('%s\n' % line)
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
|
@ -122,7 +122,7 @@ class Logger(object):
|
||||||
if not open_fd:
|
if not open_fd:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
fd = open(os.path.join(log_dir, room), 'a')
|
fd = open(os.path.join(log_dir, room), 'a', encoding='utf-8')
|
||||||
self._fds[room] = fd
|
self._fds[room] = fd
|
||||||
return fd
|
return fd
|
||||||
except IOError:
|
except IOError:
|
||||||
|
@ -150,7 +150,7 @@ class Logger(object):
|
||||||
self._check_and_create_log_dir(jid, open_fd=False)
|
self._check_and_create_log_dir(jid, open_fd=False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fd = open(os.path.join(log_dir, jid), 'rb')
|
fd = open(os.path.join(log_dir, jid), 'rb', encoding='utf-8')
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
log.info(
|
log.info(
|
||||||
'Non-existing log file (%s)',
|
'Non-existing log file (%s)',
|
||||||
|
@ -228,7 +228,8 @@ class Logger(object):
|
||||||
if not self._roster_logfile:
|
if not self._roster_logfile:
|
||||||
try:
|
try:
|
||||||
self._roster_logfile = open(
|
self._roster_logfile = open(
|
||||||
os.path.join(log_dir, 'roster.log'), 'a')
|
os.path.join(log_dir, 'roster.log'), 'a',
|
||||||
|
encoding='utf-8')
|
||||||
except IOError:
|
except IOError:
|
||||||
log.error(
|
log.error(
|
||||||
'Unable to create the log file (%s)',
|
'Unable to create the log file (%s)',
|
||||||
|
|
Loading…
Reference in a new issue