From 201aa07bc461796f47fefd5f8251168ee4c2da22 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Sun, 31 May 2015 17:50:47 -0700 Subject: [PATCH] upgrade wakatime cli to v4.0.14 --- plugin/packages/wakatime/__about__.py | 2 +- plugin/packages/wakatime/base.py | 12 ++++------- plugin/packages/wakatime/logger.py | 29 ++++++++++++++++++++++----- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/plugin/packages/wakatime/__about__.py b/plugin/packages/wakatime/__about__.py index 8208813..cc20d3f 100644 --- a/plugin/packages/wakatime/__about__.py +++ b/plugin/packages/wakatime/__about__.py @@ -1,7 +1,7 @@ __title__ = 'wakatime' __description__ = 'Common interface to the WakaTime api.' __url__ = 'https://github.com/wakatime/wakatime' -__version_info__ = ('4', '0', '13') +__version_info__ = ('4', '0', '14') __version__ = '.'.join(__version_info__) __author__ = 'Alan Hamlett' __author_email__ = 'alan@wakatime.com' diff --git a/plugin/packages/wakatime/base.py b/plugin/packages/wakatime/base.py index 22085de..c779c34 100644 --- a/plugin/packages/wakatime/base.py +++ b/plugin/packages/wakatime/base.py @@ -455,15 +455,11 @@ def main(argv=None): project_name = args.alternate_project kwargs = vars(args) - if 'project' in kwargs: - del kwargs['project'] + kwargs['project'] = project_name + kwargs['branch'] = branch + kwargs['stats'] = stats - if send_heartbeat( - project=project_name, - branch=branch, - stats=stats, - **kwargs - ): + if send_heartbeat(**kwargs): queue = Queue() while True: heartbeat = queue.pop() diff --git a/plugin/packages/wakatime/logger.py b/plugin/packages/wakatime/logger.py index 3c768cf..2dc453e 100644 --- a/plugin/packages/wakatime/logger.py +++ b/plugin/packages/wakatime/logger.py @@ -37,15 +37,17 @@ class CustomEncoder(json.JSONEncoder): class JsonFormatter(logging.Formatter): - def setup(self, timestamp, isWrite, targetFile, version, plugin, verbose): + def setup(self, timestamp, isWrite, targetFile, version, plugin, verbose, + warnings=False): self.timestamp = timestamp self.isWrite = isWrite self.targetFile = targetFile self.version = version self.plugin = plugin self.verbose = verbose + self.warnings = warnings - def format(self, record): + def format(self, record, *args): data = OrderedDict([ ('now', self.formatTime(record, self.datefmt)), ]) @@ -60,7 +62,7 @@ class JsonFormatter(logging.Formatter): if not self.isWrite: del data['isWrite'] data['level'] = record.levelname - data['message'] = record.msg + data['message'] = record.getMessage() if self.warnings else record.msg if not self.plugin: del data['plugin'] return CustomEncoder().encode(data) @@ -77,7 +79,6 @@ def set_log_level(logger, args): def setup_logging(args, version): - logging.captureWarnings(True) logger = logging.getLogger('WakaTime') set_log_level(logger, args) if len(logger.handlers) > 0: @@ -107,5 +108,23 @@ def setup_logging(args, version): ) handler.setFormatter(formatter) logger.addHandler(handler) - logging.getLogger('py.warnings').addHandler(handler) + + warnings_formatter = JsonFormatter(datefmt='%Y/%m/%d %H:%M:%S %z') + warnings_formatter.setup( + timestamp=args.timestamp, + isWrite=args.isWrite, + targetFile=args.targetFile, + version=version, + plugin=args.plugin, + verbose=args.verbose, + warnings=True, + ) + warnings_handler = logging.FileHandler(os.path.expanduser(logfile)) + warnings_handler.setFormatter(warnings_formatter) + logging.getLogger('py.warnings').addHandler(warnings_handler) + try: + logging.captureWarnings(True) + except AttributeError: + pass # Python >= 2.7 is needed to capture warnings + return logger