Skip to content
This repository was archived by the owner on Dec 21, 2024. It is now read-only.

Commit a642526

Browse files
author
Zakaria Zajac
committed
Merge pull request #26 from sullivanmatt/cleanup-exc-info
Handle error information in a more logical way
2 parents dec4d44 + 72dd046 commit a642526

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name = "python-json-logger",
11-
version = "0.1.1",
11+
version = "0.1.2",
1212
url = "http://github.com/madzak/python-json-logger",
1313
license = "BSD",
1414
description = "A python library adding a json log formatter",

src/pythonjsonlogger/jsonlogger.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import json
77
import re
88
import datetime
9+
import traceback
10+
11+
from inspect import istraceback
912

1013
#Support order in python 2.7 and 3
1114
try:
@@ -73,6 +76,11 @@ def _default_json_handler(obj):
7376
return obj.isoformat()
7477
elif isinstance(obj, datetime.time):
7578
return obj.strftime('%H:%M')
79+
elif istraceback(obj):
80+
tb = ''.join(traceback.format_tb(obj))
81+
return tb.strip()
82+
elif isinstance(obj, Exception):
83+
return "Exception: %s" % str(obj)
7684
return str(obj)
7785
self.json_default = _default_json_handler
7886
self._required_fields = self.parse()

0 commit comments

Comments
 (0)