fix character encoding problem with localized datetime in log
This commit is contained in:
parent
59de87799e
commit
d714bb9299
1 changed files with 7 additions and 4 deletions
|
@ -38,15 +38,18 @@ class CustomEncoder(json.JSONEncoder):
|
||||||
class JsonFormatter(logging.Formatter):
|
class JsonFormatter(logging.Formatter):
|
||||||
|
|
||||||
def setup(self, timestamp, isWrite, targetFile, version, plugin):
|
def setup(self, timestamp, isWrite, targetFile, version, plugin):
|
||||||
|
encoding = sys.getfilesystemencoding()
|
||||||
|
|
||||||
self.timestamp = timestamp
|
self.timestamp = timestamp
|
||||||
self.isWrite = isWrite
|
self.isWrite = isWrite
|
||||||
self.targetFile = targetFile
|
self.targetFile = targetFile.decode(encoding, 'ignore')
|
||||||
self.version = version
|
self.version = version
|
||||||
self.plugin = plugin
|
self.plugin = plugin
|
||||||
|
|
||||||
def format(self, record):
|
def format(self, record):
|
||||||
|
now = self.formatTime(record, self.datefmt).decode('utf-8', 'ignore')
|
||||||
data = OrderedDict([
|
data = OrderedDict([
|
||||||
('now', self.formatTime(record, self.datefmt)),
|
('now', now),
|
||||||
('version', self.version),
|
('version', self.version),
|
||||||
('plugin', self.plugin),
|
('plugin', self.plugin),
|
||||||
('time', self.timestamp),
|
('time', self.timestamp),
|
||||||
|
@ -76,7 +79,7 @@ def setup_logging(args, version):
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
set_log_level(logger, args)
|
set_log_level(logger, args)
|
||||||
if len(logger.handlers) > 0:
|
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(
|
formatter.setup(
|
||||||
timestamp=args.timestamp,
|
timestamp=args.timestamp,
|
||||||
isWrite=args.isWrite,
|
isWrite=args.isWrite,
|
||||||
|
@ -90,7 +93,7 @@ def setup_logging(args, version):
|
||||||
if not logfile:
|
if not logfile:
|
||||||
logfile = '~/.wakatime.log'
|
logfile = '~/.wakatime.log'
|
||||||
handler = logging.FileHandler(os.path.expanduser(logfile))
|
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(
|
formatter.setup(
|
||||||
timestamp=args.timestamp,
|
timestamp=args.timestamp,
|
||||||
isWrite=args.isWrite,
|
isWrite=args.isWrite,
|
||||||
|
|
Loading…
Reference in a new issue