Skip to content

Commit b25943a

Browse files
authored
Fix stacktrace format (#50)
1 parent 6fcea39 commit b25943a

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

sap/cf_logging/formatters/stacktrace_formatter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99

1010
def format_stacktrace(stacktrace):
1111
"""
12-
Removes newline and tab characters
12+
Removes tab characters
1313
Truncates stacktrace to maximum size
1414
1515
:param stacktrace: string representation of a stacktrace
1616
"""
1717
if not isinstance(stacktrace, str):
1818
return ''
1919

20-
stacktrace = re.sub('\n|\t', ' ', stacktrace)
20+
stacktrace = re.sub('\t', ' ', stacktrace)
2121

2222
if len(stacktrace) <= constants.STACKTRACE_MAX_SIZE:
2323
return stacktrace
@@ -30,8 +30,8 @@ def format_stacktrace(stacktrace):
3030
stacktrace, (constants.STACKTRACE_MAX_SIZE // 3) * 2
3131
)
3232

33-
new_stacktrace = "-------- STACK TRACE TRUNCATED --------" + stacktrace_beginning +\
34-
"-------- OMITTED --------" + stacktrace_end
33+
new_stacktrace = "-------- STACK TRACE TRUNCATED --------\n" + stacktrace_beginning +\
34+
"-------- OMITTED --------\n" + stacktrace_end
3535

3636
return new_stacktrace
3737

sap/cf_logging/record/simple_log_record.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,12 @@ def format(self):
7272
'logger': self.name,
7373
'thread': self.threadName,
7474
'level': self.levelname,
75-
'line_no': self.lineno,
7675
'msg': self.getMessage(),
7776
})
7877

7978
if self.levelno == logging.ERROR and self.exc_info:
8079
stacktrace = ''.join(traceback.format_exception(*self.exc_info))
81-
record['stacktrace'] = format_stacktrace(stacktrace)
80+
record['stacktrace'] = format_stacktrace(stacktrace).split('\n')
8281

8382
record.update(self.extra)
8483
if len(self.custom_fields) > 0:

tests/log_schemas.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
'logger': u.string(u.WORD),
2323
'thread': u.string(u.WORD),
2424
'level': u.enum(u.LEVEL),
25-
'line_no': u.pos_num(),
2625
'written_at': u.iso_datetime(),
2726
'written_ts': u.pos_num(),
2827
'msg': u.string(u.WORD),

tests/unit/formatters/test_stacktrace_formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ def test_stacktrace_truncated(monkeypatch):
1919
""" Test that stacktrace is truncated when bigger than the stacktrace maximum size """
2020
monkeypatch.setattr('sap.cf_logging.core.constants.STACKTRACE_MAX_SIZE', 120)
2121

22-
formatted = format_stacktrace(STACKTRACE)
22+
formatted = ''.join(format_stacktrace(STACKTRACE))
2323
assert "TRUNCATED" in formatted
2424
assert "OMITTED" in formatted

0 commit comments

Comments
 (0)