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 3
3
import logging
4
4
import socket
5
5
import sys
6
+ import traceback
6
7
7
8
try :
8
9
import simplejson as json
@@ -22,6 +23,10 @@ class FluentRecordFormatter(logging.Formatter, object):
22
23
23
24
Best used with server storing data in an ElasticSearch cluster for example.
24
25
26
+ Supports an extra `exc_traceback` format argument that represents a
27
+ traceback when logging an exception as return by
28
+ :meth:`traceback.extract_tb`.
29
+
25
30
:param fmt: a dict with format string as values to map to provided keys.
26
31
"""
27
32
def __init__ (self , fmt = None , datefmt = None ):
@@ -47,9 +52,17 @@ def format(self, record):
47
52
super (FluentRecordFormatter , self ).format (record )
48
53
# Add ours
49
54
record .hostname = self .hostname
55
+
50
56
# Apply format
51
- data = dict ([(key , value % record .__dict__ )
52
- for key , value in self ._fmt_dict .items ()])
57
+ data = {}
58
+ for key , value in self ._fmt_dict .items ():
59
+ if value .find ('%(exc_traceback)' ) >= 0 :
60
+ if record .exc_info :
61
+ data [key ] = traceback .extract_tb (record .exc_info [2 ])
62
+ else :
63
+ data [key ] = None
64
+ else :
65
+ data [key ] = value % record .__dict__
53
66
54
67
self ._structuring (data , record .msg )
55
68
return data
You can’t perform that action at this time.
0 commit comments