Skip to content

Commit

Permalink
fix: unintended exception omittion (#736)
Browse files Browse the repository at this point in the history
  • Loading branch information
shkumagai authored Sep 25, 2023
1 parent f1e8955 commit 022dc54
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions google/cloud/logging_v2/handlers/structured_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,18 @@ def __init__(
log_filter = CloudLoggingFilter(project=project_id, default_labels=labels)
self.addFilter(log_filter)

class _Formatter(logging.Formatter):
"""Formatter to format log message without traceback"""

def format(self, record):
"""Ignore exception info to avoid duplicating it
https://github.com/googleapis/python-logging/issues/382
"""
record.message = record.getMessage()
return self.formatMessage(record)

# make logs appear in GCP structured logging format
self._gcp_formatter = logging.Formatter(GCP_FORMAT)
self._gcp_formatter = _Formatter(GCP_FORMAT)

self._json_encoder_cls = json_encoder_cls or json.JSONEncoder

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

record._payload_str = payload or ""
# remove exception info to avoid duplicating it
# https://github.com/googleapis/python-logging/issues/382
record.exc_info = None
record.exc_text = None
# convert to GCP structred logging format
# convert to GCP structured logging format
gcp_payload = self._gcp_formatter.format(record)
return gcp_payload

Expand Down

0 comments on commit 022dc54

Please sign in to comment.