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 33import logging
44import socket
55import sys
6+ import traceback
67
78try :
89 import simplejson as json
@@ -22,6 +23,10 @@ class FluentRecordFormatter(logging.Formatter, object):
2223
2324 Best used with server storing data in an ElasticSearch cluster for example.
2425
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+
2530 :param fmt: a dict with format string as values to map to provided keys.
2631 """
2732 def __init__ (self , fmt = None , datefmt = None ):
@@ -47,9 +52,17 @@ def format(self, record):
4752 super (FluentRecordFormatter , self ).format (record )
4853 # Add ours
4954 record .hostname = self .hostname
55+
5056 # 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__
5366
5467 self ._structuring (data , record .msg )
5568 return data
You can’t perform that action at this time.
0 commit comments