-
Notifications
You must be signed in to change notification settings - Fork 57
Closed
Labels
api: loggingIssues related to the googleapis/python-logging API.Issues related to the googleapis/python-logging API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
The StructuredLogHandler appends a Traceback after the json structured log message.
This causes a second unstructured log entry with just the traceback when the handler is used in a Google Cloud Function.
Code example
import logging
from google.cloud.logging.handlers import StructuredLogHandler
logger = logging.getLogger()
logger.handlers.clear()
logger.addHandler(StructuredLogHandler())
try:
raise Exception("Test")
except Exception:
logger.exception("Failed")Output
{"message": "Failed\nTraceback (most recent call last):\n File \"main.py\", line 10, in <module>\n raise Exception(\"Test\")\nException: Test", "severity": "ERROR", "logging.googleapis.com/labels": {}, "logging.googleapis.com/trace": "", "logging.googleapis.com/spanId": "", "logging.googleapis.com/sourceLocation": {"line": 12, "file": "main.py", "function": "<module>"}, "httpRequest": {} }
Traceback (most recent call last):
File "main.py", line 10, in <module>
raise Exception("Test")
Exception: Test
The traceback appears twice. Once inside the structured log message and again after it. This happens because a logging.Formatter is used which always appends the traceback if exc_info or exc_text is present.
lutostag
Metadata
Metadata
Assignees
Labels
api: loggingIssues related to the googleapis/python-logging API.Issues related to the googleapis/python-logging API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.