File tree 1 file changed +15
-2
lines changed
1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import logging
4
4
import socket
5
+ import traceback
5
6
6
7
try :
7
8
import simplejson as json
@@ -21,6 +22,10 @@ class FluentRecordFormatter(logging.Formatter, object):
21
22
22
23
Best used with server storing data in an ElasticSearch cluster for example.
23
24
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
+
24
29
:param fmt: a dict with format string as values to map to provided keys.
25
30
"""
26
31
def __init__ (self , fmt = None , datefmt = None ):
@@ -42,9 +47,17 @@ def format(self, record):
42
47
super (FluentRecordFormatter , self ).format (record )
43
48
# Add ours
44
49
record .hostname = self .hostname
50
+
45
51
# 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__
48
61
49
62
self ._structuring (data , record .msg )
50
63
return data
You can’t perform that action at this time.
0 commit comments