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
@@ -16,6 +17,10 @@ class FluentRecordFormatter(logging.Formatter, object):
1617
1718 Best used with server storing data in an ElasticSearch cluster for example.
1819
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+
1924 :param fmt: a dict with format string as values to map to provided keys.
2025 """
2126 def __init__ (self , fmt = None , datefmt = None ):
@@ -37,9 +42,17 @@ def format(self, record):
3742 super (FluentRecordFormatter , self ).format (record )
3843 # Add ours
3944 record .hostname = self .hostname
45+
4046 # 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__
4356
4457 self ._structuring (data , record .msg )
4558 return data
You can’t perform that action at this time.
0 commit comments