Skip to content

Commit

Permalink
#6 fix: _JsonFormatter__extra in log
Browse files Browse the repository at this point in the history
  • Loading branch information
MyColorfulDays committed Jan 2, 2021
1 parent d126b1c commit 38b8dcb
Showing 5 changed files with 50 additions and 8 deletions.
4 changes: 2 additions & 2 deletions jsonformatter/__init__.py
Original file line number Diff line number Diff line change
@@ -12,5 +12,5 @@

__all__ = ['JsonFormatter', 'basicConfig']

version = "0.3.0"
version_info = (0, 3, 0)
version = "0.3.1"
version_info = (0, 3, 1)
2 changes: 1 addition & 1 deletion jsonformatter/jsonformatter.py
Original file line number Diff line number Diff line change
@@ -382,7 +382,7 @@ def _set_fmt_to_result():
record.asctime = self.formatTime(record, self.datefmt)

# pop stored __extra start
extra = record.__dict__.pop('__extra', None)
extra = record.__dict__.pop('__extra', None) or record.__dict__.pop('_JsonFormatter__extra', None)
if extra is None:
# extra is dictionary
extra = self.getRecordExtraAttrs(record)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@

setup(
name='jsonformatter',
version='0.3.0',
version='0.3.1',
description=(
'Python log in json format.'
),
21 changes: 21 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
@@ -405,6 +405,27 @@ def test_mix_extra_position_is_head(self):
root.info('test mix extra position is head',
extra={'extra': 'extra content'})

def test_mix_extra_multi_formatter(self):
root = logging.getLogger()
root.setLevel(logging.INFO)

fh = logging.FileHandler('jsonformatter.log')
formatter = JsonFormatter(
ensure_ascii=False, mix_extra=True, indent=4)
fh.setFormatter(formatter)
fh.setLevel(logging.INFO)
root.addHandler(fh)

sh = logging.StreamHandler()
formatter = JsonFormatter(
ensure_ascii=False, mix_extra=True, indent=4)
sh.setFormatter(formatter)
sh.setLevel(logging.INFO)
root.addHandler(sh)

root.info('test mix extra multi formatter',
extra={'extra': 'extra content'})

def test_mix_extra_position_is_mix(self):
root = logging.getLogger()
root.setLevel(logging.INFO)
29 changes: 25 additions & 4 deletions test/test_windows.py
Original file line number Diff line number Diff line change
@@ -153,7 +153,7 @@ def test_percent_style_unicode(self):
sh.setLevel(logging.INFO)

root.addHandler(sh)
root.info('test percent style unicode: %s', 'ÖÐÎÄ')
root.info('test percent style unicode: %s', '����')

def test_format_style_unicode(self):
root = logging.getLogger()
@@ -167,7 +167,7 @@ def test_format_style_unicode(self):
sh.setLevel(logging.INFO)

root.addHandler(sh)
root.info('test format style unicode: %s', 'ÖÐÎÄ')
root.info('test format style unicode: %s', '����')

def test_template_style_unicode(self):
root = logging.getLogger()
@@ -181,7 +181,7 @@ def test_template_style_unicode(self):
sh.setLevel(logging.INFO)

root.addHandler(sh)
root.info('test template style unicode: %s', 'ÖÐÎÄ')
root.info('test template style unicode: %s', '����')

def test_dict_format(self):
DICT_FORMAT = {
@@ -348,7 +348,7 @@ def test_json_dumps_parameter_ensure_ascii_false(self):

root.addHandler(sh)

root.info('test json dumps parameter `ensure_ascii` False: ÖÐÎÄ')
root.info('test json dumps parameter `ensure_ascii` False: ����')

def test_file_config(self):
fileConfig(os.path.join(os.path.dirname(
@@ -416,6 +416,27 @@ def test_mix_extra_position_is_head(self):
root.info('test mix extra position is head',
extra={'extra': 'extra content'})

def test_mix_extra_multi_formatter(self):
root = logging.getLogger()
root.setLevel(logging.INFO)

fh = logging.FileHandler('jsonformatter.log')
formatter = JsonFormatter(
ensure_ascii=False, mix_extra=True, indent=4)
fh.setFormatter(formatter)
fh.setLevel(logging.INFO)
root.addHandler(fh)

sh = logging.StreamHandler()
formatter = JsonFormatter(
ensure_ascii=False, mix_extra=True, indent=4)
sh.setFormatter(formatter)
sh.setLevel(logging.INFO)
root.addHandler(sh)

root.info('test mix extra multi formatter',
extra={'extra': 'extra content'})

def test_mix_extra_position_is_mix(self):
root = logging.getLogger()
root.setLevel(logging.INFO)

0 comments on commit 38b8dcb

Please sign in to comment.