Skip to content

Commit

Permalink
more robust logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ebrehault committed Dec 17, 2015
1 parent 43c760a commit 38c1ee8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/rapido/plone/browser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
from rapido.plone.app import get_app


class PythonObjectEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(
obj,
(list, dict, str, unicode, int, float, bool, type(None))
):
return json.JSONEncoder.default(self, obj)
return {'_not_serializable': str(obj)}


class RapidoView(BrowserView):
implements(IPublishTraverse)

Expand Down Expand Up @@ -99,7 +109,7 @@ def __call__(self):
if len(self.path) == 2 and self.path[1] == '_log':
messages = self.get_app_messages()
self.request.response.setHeader('content-type', 'application/json')
return json.dumps(messages)
return json.dumps(messages, cls=PythonObjectEncoder)

if "application/json" in self.request.getHeader('Accept', ''):
result = self.json()
Expand Down

0 comments on commit 38c1ee8

Please sign in to comment.