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
@@ -16,6 +17,10 @@ class FluentRecordFormatter(logging.Formatter, object):
16
17
17
18
Best used with server storing data in an ElasticSearch cluster for example.
18
19
20
+ Supports an extra `exc_traceback` format argument that represents a
21
+ traceback when logging an exception as return by
22
+ :meth:`traceback.extract_tb`.
23
+
19
24
:param fmt: a dict with format string as values to map to provided keys.
20
25
"""
21
26
def __init__ (self , fmt = None , datefmt = None ):
@@ -37,9 +42,17 @@ def format(self, record):
37
42
super (FluentRecordFormatter , self ).format (record )
38
43
# Add ours
39
44
record .hostname = self .hostname
45
+
40
46
# Apply format
41
- data = dict ([(key , value % record .__dict__ )
42
- for key , value in self ._fmt_dict .items ()])
47
+ data = {}
48
+ for key , value in self ._fmt_dict .items ():
49
+ if value .find ('%(exc_traceback)' ) >= 0 :
50
+ if record .exc_info :
51
+ data [key ] = traceback .extract_tb (record .exc_info [2 ])
52
+ else :
53
+ data [key ] = None
54
+ else :
55
+ data [key ] = value % record .__dict__
43
56
44
57
self ._structuring (data , record .msg )
45
58
return data
You can’t perform that action at this time.
0 commit comments