summaryrefslogtreecommitdiff
path: root/Mailman/Logging/Logger.py
diff options
context:
space:
mode:
authorbwarsaw2002-09-17 21:57:27 +0000
committerbwarsaw2002-09-17 21:57:27 +0000
commitc549ab80a9d6b4ad16651d2f4d8394b57c8b4cf3 (patch)
treee6ab175ee3d127ee64622c4d30c513e0a49f50bb /Mailman/Logging/Logger.py
parent090ae7a5036b477ab57001e172e5944130211f1b (diff)
downloadmailman-c549ab80a9d6b4ad16651d2f4d8394b57c8b4cf3.tar.gz
mailman-c549ab80a9d6b4ad16651d2f4d8394b57c8b4cf3.tar.zst
mailman-c549ab80a9d6b4ad16651d2f4d8394b57c8b4cf3.zip
Diffstat (limited to 'Mailman/Logging/Logger.py')
-rw-r--r--Mailman/Logging/Logger.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/Mailman/Logging/Logger.py b/Mailman/Logging/Logger.py
index c646e3788..64b291208 100644
--- a/Mailman/Logging/Logger.py
+++ b/Mailman/Logging/Logger.py
@@ -18,10 +18,17 @@
import sys
import os
+import codecs
+from types import StringType
from Mailman import mm_cfg
from Mailman.Logging.Utils import _logexc
+# Set this to the encoding to be used for your log file output. If set to
+# None, then it uses your system's default encoding. Otherwise, it must be an
+# encoding string appropriate for codecs.open().
+LOG_ENCODING = 'iso-8859-1'
+
class Logger:
@@ -37,6 +44,7 @@ class Logger:
self.__filename = os.path.join(mm_cfg.LOG_DIR, category)
self.__fp = None
self.__nofail = nofail
+ self.__encoding = LOG_ENCODING or sys.getdefaultencoding()
if immediate:
self.__get_f()
@@ -53,7 +61,13 @@ class Logger:
try:
ou = os.umask(002)
try:
- f = self.__fp = open(self.__filename, 'a+', 1)
+ try:
+ f = codecs.open(
+ self.__filename, 'a+', self.__encoding, 'replace',
+ 1)
+ except codecs.LookupError:
+ f = open(self.__filename, 'a+', 1)
+ self.__fp = f
finally:
os.umask(ou)
except IOError, e:
@@ -70,6 +84,8 @@ class Logger:
f.flush()
def write(self, msg):
+ if isinstance(msg, StringType):
+ msg = unicode(msg, self.__encoding)
f = self.__get_f()
try:
f.write(msg)