-
Notifications
You must be signed in to change notification settings - Fork 25
exception handling in celery and formatting log.info() #18
Description
logs are arriving in kibana, all is working! thanks again for helping me out earlier.
Still two probably simple to cover questions on the code.
I have celery tasks running, related to users. these turn into results.
I now wanted to add results and user details also in kibana, including exceptions (to prevent time-out) when things go bad inside my taks.
I tried the: log.info('info to log') and it puts the "info to log" inside the "raw message" inside kibana.
My two questions:
-
If I wanted an output that returns a "structured" by kibana interpretable output, so that the message.raw is transformed in message.request.id, message.request.name, etc. How do I do that in an easy way? Or do I manually format my log.info()-input in json-style?
-
For exception handling, i noticed your "ErrorLogObject"-class. How does it work? As I am in the celery task, and requests are not serialisable, it is impossible to pass it on, does it mean I will not be able to use this here?
EDIT:
I figured out how ErrorLogObject works in views.py:
- request is needed - so my question is still valid for the case of a celery task
- I used
except Exception as e:and used de "e" as exception input - I set duration as an integer being "zero" which allows me to push error notifications to kibana.
EDIT 2:
Tried minimalistic json output in the log.error, something like:
log.error('{{ \'raw\' : {{ \'x\':{0}, \'y\':{1} }} }}'.format( x , y ) )
However, not splitting the "message.raw" into "message.x" and "message.y"