Skip to content

Commit 022dc54

Browse files
authored
fix: unintended exception omittion (#736)
1 parent f1e8955 commit 022dc54

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

google/cloud/logging_v2/handlers/structured_log.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,18 @@ def __init__(
7979
log_filter = CloudLoggingFilter(project=project_id, default_labels=labels)
8080
self.addFilter(log_filter)
8181

82+
class _Formatter(logging.Formatter):
83+
"""Formatter to format log message without traceback"""
84+
85+
def format(self, record):
86+
"""Ignore exception info to avoid duplicating it
87+
https://github.com/googleapis/python-logging/issues/382
88+
"""
89+
record.message = record.getMessage()
90+
return self.formatMessage(record)
91+
8292
# make logs appear in GCP structured logging format
83-
self._gcp_formatter = logging.Formatter(GCP_FORMAT)
93+
self._gcp_formatter = _Formatter(GCP_FORMAT)
8494

8595
self._json_encoder_cls = json_encoder_cls or json.JSONEncoder
8696

@@ -115,11 +125,7 @@ def format(self, record):
115125
payload = '"message": {},'.format(encoded_message)
116126

117127
record._payload_str = payload or ""
118-
# remove exception info to avoid duplicating it
119-
# https://github.com/googleapis/python-logging/issues/382
120-
record.exc_info = None
121-
record.exc_text = None
122-
# convert to GCP structred logging format
128+
# convert to GCP structured logging format
123129
gcp_payload = self._gcp_formatter.format(record)
124130
return gcp_payload
125131

0 commit comments

Comments
 (0)