Skip to content

Commit

Permalink
Include code to hand array's of dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Furr committed Jan 17, 2019
1 parent 20b0dc2 commit bde6034
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 9 additions & 2 deletions mongolog/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def check_keys(self, record):
if not isinstance(record['msg'], dict):
return record

for k, v in record['msg'].items():
for k, v in list(record['msg'].items()):
self._check_keys(k, v, record['msg'])

return record
Expand All @@ -165,9 +165,16 @@ def _check_keys(self, k, v, _dict):
_dict[self.new_key(k)] = _dict.pop(k)

if isinstance(v, dict):
for nk, vk in v.items():
for nk, vk in list(v.items()):
self._check_keys(nk, vk, v)

# We could also have an array of dictionaries so we check those as well.
if isinstance(v, list):
for l in v:
if isinstance(l, dict):
for nk, vk in list(l.items()):
self._check_keys(nk, vk, l)

def new_key(self, key):
"""
mongo < 3.6
Expand Down
8 changes: 6 additions & 2 deletions mongolog/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_middleware(self):
response = c.get(reverse("home"))
self.assertContains(response, "HERE YOU ARE ON monglog/home.html")

def test_dot_in_key(self):
def test_special_chars_in_key(self):
console.debug(self)
self.logger.info({
'META': {
Expand All @@ -170,7 +170,11 @@ def test_dot_in_key(self):
'blah.blah': 'blah',
'$blah$blah': 'blah',
'array': [
{'$test': 'test'}
{
'$test': 'test',
'test$test': 'test',
'.test.test': 'test',
}
],
'META3': {
'meta3.meta3': 'meta3',
Expand Down

0 comments on commit bde6034

Please sign in to comment.