fix character encoding problem with localized datetime in log

This commit is contained in:
Alan Hamlett 2013-12-03 02:34:00 +01:00
parent 59de87799e
commit d714bb9299
1 changed files with 7 additions and 4 deletions

View File

@ -38,15 +38,18 @@ class CustomEncoder(json.JSONEncoder):
class JsonFormatter(logging.Formatter):
def setup(self, timestamp, isWrite, targetFile, version, plugin):
encoding = sys.getfilesystemencoding()
self.timestamp = timestamp
self.isWrite = isWrite
self.targetFile = targetFile
self.targetFile = targetFile.decode(encoding, 'ignore')
self.version = version
self.plugin = plugin
def format(self, record):
now = self.formatTime(record, self.datefmt).decode('utf-8', 'ignore')
data = OrderedDict([
('now', self.formatTime(record, self.datefmt)),
('now', now),
('version', self.version),
('plugin', self.plugin),
('time', self.timestamp),
@ -76,7 +79,7 @@ def setup_logging(args, version):
logger = logging.getLogger()
set_log_level(logger, args)
if len(logger.handlers) > 0:
formatter = JsonFormatter(datefmt='%a %b %d %H:%M:%S %Z %Y')
formatter = JsonFormatter(datefmt='%Y/%m/%d %H:%M:%S %z')
formatter.setup(
timestamp=args.timestamp,
isWrite=args.isWrite,
@ -90,7 +93,7 @@ def setup_logging(args, version):
if not logfile:
logfile = '~/.wakatime.log'
handler = logging.FileHandler(os.path.expanduser(logfile))
formatter = JsonFormatter(datefmt='%a %b %d %H:%M:%S %Z %Y')
formatter = JsonFormatter(datefmt='%Y/%m/%d %H:%M:%S %z')
formatter.setup(
timestamp=args.timestamp,
isWrite=args.isWrite,