File tree 3 files changed +28
-6
lines changed
3 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ def format(self, record):
62
62
return record .msg
63
63
64
64
if record .levelname == "ERROR" or record .levelname == "CRITICAL" :
65
- exception , stack_trace = self ._parse_exc (record . exc_info )
65
+ exception , stack_trace = self ._parse_exc (record )
66
66
67
67
return (
68
68
"{color}{levelname}{nc}: {description}" "{stack_trace}\n "
@@ -122,13 +122,15 @@ def _walk_exc(self, exc_info):
122
122
123
123
return exc_list , tb_list
124
124
125
- def _parse_exc (self , exc_info ):
126
- if not exc_info :
125
+ def _parse_exc (self , record ):
126
+ tb_only = getattr (record , "tb_only" , False )
127
+
128
+ if not record .exc_info :
127
129
return (None , "" )
128
130
129
- exc_list , tb_list = self ._walk_exc (exc_info )
131
+ exc_list , tb_list = self ._walk_exc (record . exc_info )
130
132
131
- exception = ": " .join (exc_list )
133
+ exception = None if tb_only else ": " .join (exc_list )
132
134
133
135
if self ._current_level () == logging .DEBUG :
134
136
stack_trace = (
Original file line number Diff line number Diff line change @@ -60,7 +60,8 @@ def main(argv=None):
60
60
except Exception as exc : # pylint: disable=broad-except
61
61
if isinstance (exc , OSError ) and exc .errno == errno .EMFILE :
62
62
logger .exception (
63
- "too many open files, please increase your `ulimit`"
63
+ "too many open files, please increase your `ulimit`" ,
64
+ extra = {"tb_only" : True },
64
65
)
65
66
else :
66
67
logger .exception ("unexpected error" )
Original file line number Diff line number Diff line change @@ -102,6 +102,25 @@ def test_exception_under_verbose(self, caplog):
102
102
103
103
assert expected == formatter .format (caplog .records [0 ])
104
104
105
+ def test_tb_only (self , caplog ):
106
+ with caplog .at_level (logging .DEBUG , logger = "dvc" ):
107
+ try :
108
+ raise Exception ("description" )
109
+ except Exception :
110
+ stack_trace = traceback .format_exc ()
111
+ logger .exception ("something" , extra = {"tb_only" : True })
112
+
113
+ expected = (
114
+ "{red}ERROR{nc}: something\n "
115
+ "{red}{line}{nc}\n "
116
+ "{stack_trace}"
117
+ "{red}{line}{nc}\n " .format (
118
+ line = "-" * 60 , stack_trace = stack_trace , ** colors
119
+ )
120
+ )
121
+
122
+ assert expected == formatter .format (caplog .records [0 ])
123
+
105
124
def test_nested_exceptions (self , caplog ):
106
125
with caplog .at_level (logging .DEBUG , logger = "dvc" ):
107
126
try :
You can’t perform that action at this time.
0 commit comments