From 06a56179461bf6e637debc8f07a5eb67216c43e7 Mon Sep 17 00:00:00 2001 From: ComplYue Date: Mon, 1 Aug 2016 22:49:57 +0800 Subject: [PATCH 1/4] ignore PyCharm project settings --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 72364f9..9e00340 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,6 @@ ENV/ # Rope project settings .ropeproject + +# PyCharm project settings +.idea/ From 909592bdb2d505b19676cf7c7f03881fef9df821 Mon Sep 17 00:00:00 2001 From: ComplYue Date: Tue, 2 Aug 2016 02:53:58 +0800 Subject: [PATCH 2/4] reduce runtime exceptions by shimming OrderedDict with dict --- bunyan/formatter.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bunyan/formatter.py b/bunyan/formatter.py index 6cbf391..617a6f5 100644 --- a/bunyan/formatter.py +++ b/bunyan/formatter.py @@ -16,6 +16,7 @@ try: from collections import OrderedDict except ImportError: + OrderedDict = dict pass def object_startswith(key, value): @@ -149,10 +150,7 @@ def format(self, record): if record.exc_info and not message_dict.get('exc_info'): message_dict['exc_info'] = self.formatException(record.exc_info) - try: - log_record = OrderedDict() - except NameError: - log_record = {} + log_record = OrderedDict() self.add_fields(log_record, record, message_dict) log_record = self.process_log_record(log_record) From 634ebcc4dce55c5e09a6e0ce46a946d835722c7a Mon Sep 17 00:00:00 2001 From: ComplYue Date: Tue, 2 Aug 2016 03:08:23 +0800 Subject: [PATCH 3/4] add support for bunyan style log method: log.info({foo: 'bar'}, 'hi'); --- bunyan/formatter.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bunyan/formatter.py b/bunyan/formatter.py index 617a6f5..02a2001 100644 --- a/bunyan/formatter.py +++ b/bunyan/formatter.py @@ -138,7 +138,12 @@ def format(self, record): if isinstance(record.msg, dict): message_dict = record.msg - record.message = None + if len(record.args) == 1 and isinstance(record.args[0], str): + # bunyan style log method: fields object + msg string + record.msg = record.args[0] + record.message = record.args[0] % message_dict + else: + record.message = None else: record.message = record.getMessage() # only format time if needed From 5e41d89656a60c65325fe206496df9ef60f90843 Mon Sep 17 00:00:00 2001 From: ComplYue Date: Mon, 23 Jan 2017 15:42:25 +0800 Subject: [PATCH 4/4] use simplejson to workaround NaN/Infinity --- bunyan/formatter.py | 4 ++-- requirements.txt | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bunyan/formatter.py b/bunyan/formatter.py index 02a2001..5142f52 100644 --- a/bunyan/formatter.py +++ b/bunyan/formatter.py @@ -4,7 +4,7 @@ Provides logging compatibility with Bunyan standard and enceforth CLI. """ import datetime -import json +import simplejson as json import logging import re import socket @@ -128,7 +128,7 @@ def jsonify_log_record(self, log_record): """ Returns a json string of the log record. """ - return json.dumps(log_record, default = self.json_default) + return json.dumps(log_record, default = self.json_default, ignore_nan=True) def format(self, record): """ diff --git a/requirements.txt b/requirements.txt index e69de29..322630e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1 @@ +simplejson