Skip to content

Commit a579056

Browse files
spaceonejosheppinette
authored andcommitted
refactor: simplify traceback generation
Resolves #31
1 parent 42c2e47 commit a579056

1 file changed

Lines changed: 1 addition & 9 deletions

File tree

src/logfmter/formatter.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import io
21
import logging
32
import numbers
43
import traceback
5-
from contextlib import closing
64
from types import TracebackType
75
from typing import Dict, List, Optional, Tuple, Type, cast
86

@@ -88,14 +86,8 @@ def format_exc_info(cls, exc_info: ExcInfo) -> str:
8886
except Exception:
8987
logging.exception()
9088
"""
91-
_type, exc, tb = exc_info
92-
93-
with closing(io.StringIO()) as sio:
94-
traceback.print_exception(_type, exc, tb, None, sio)
95-
value = sio.getvalue()
96-
9789
# Tracebacks have a single trailing newline that we don't need.
98-
value = value.rstrip("\n")
90+
value = "".join(traceback.format_exception(*exc_info)).rstrip("\n")
9991

10092
return cls.format_string(value)
10193

0 commit comments

Comments
 (0)