File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 22
33import logging
44import socket
5+ import traceback
56
67try :
78 import simplejson as json
@@ -21,6 +22,10 @@ class FluentRecordFormatter(logging.Formatter, object):
2122
2223 Best used with server storing data in an ElasticSearch cluster for example.
2324
25+ Supports an extra `exc_traceback` format argument that represents a
26+ traceback when logging an exception as return by
27+ :meth:`traceback.extract_tb`.
28+
2429 :param fmt: a dict with format string as values to map to provided keys.
2530 """
2631 def __init__ (self , fmt = None , datefmt = None ):
@@ -42,9 +47,17 @@ def format(self, record):
4247 super (FluentRecordFormatter , self ).format (record )
4348 # Add ours
4449 record .hostname = self .hostname
50+
4551 # Apply format
46- data = dict ([(key , value % record .__dict__ )
47- for key , value in self ._fmt_dict .items ()])
52+ data = {}
53+ for key , value in self ._fmt_dict .items ():
54+ if value .find ('%(exc_traceback)' ) >= 0 :
55+ if record .exc_info :
56+ data [key ] = traceback .extract_tb (record .exc_info [2 ])
57+ else :
58+ data [key ] = None
59+ else :
60+ data [key ] = value % record .__dict__
4861
4962 self ._structuring (data , record .msg )
5063 return data
You can’t perform that action at this time.
0 commit comments