File tree Expand file tree Collapse file tree 3 files changed +28
-6
lines changed Expand file tree Collapse file tree 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):
6262 return record .msg
6363
6464 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 )
6666
6767 return (
6868 "{color}{levelname}{nc}: {description}" "{stack_trace}\n "
@@ -122,13 +122,15 @@ def _walk_exc(self, exc_info):
122122
123123 return exc_list , tb_list
124124
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 :
127129 return (None , "" )
128130
129- exc_list , tb_list = self ._walk_exc (exc_info )
131+ exc_list , tb_list = self ._walk_exc (record . exc_info )
130132
131- exception = ": " .join (exc_list )
133+ exception = None if tb_only else ": " .join (exc_list )
132134
133135 if self ._current_level () == logging .DEBUG :
134136 stack_trace = (
Original file line number Diff line number Diff line change @@ -60,7 +60,8 @@ def main(argv=None):
6060 except Exception as exc : # pylint: disable=broad-except
6161 if isinstance (exc , OSError ) and exc .errno == errno .EMFILE :
6262 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 },
6465 )
6566 else :
6667 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):
102102
103103 assert expected == formatter .format (caplog .records [0 ])
104104
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+
105124 def test_nested_exceptions (self , caplog ):
106125 with caplog .at_level (logging .DEBUG , logger = "dvc" ):
107126 try :
You can’t perform that action at this time.
0 commit comments