Skip to content
Merged
6 changes: 5 additions & 1 deletion google/cloud/logging_v2/handlers/structured_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,8 @@ def emit(self, record):
def emit_instrumentation_info(self):
google.cloud.logging_v2._instrumentation_emitted = True
diagnostic_object = _create_diagnostic_entry()
logging.info(diagnostic_object.payload)
struct_logger = logging.getLogger(__name__)
struct_logger.addHandler(self)
struct_logger.setLevel(logging.INFO)
struct_logger.info(diagnostic_object.payload)
struct_logger.handlers.clear()
3 changes: 2 additions & 1 deletion tests/unit/handlers/test_structured_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,8 @@ def test_valid_instrumentation_info(self):
import mock
import json

with mock.patch.object(logging, "info") as mock_log:
logger = logging.getLogger("google.cloud.logging_v2.handlers.structured_log")
with mock.patch.object(logger, "info") as mock_log:
handler = self._make_one()
handler.emit_instrumentation_info()
mock_log.assert_called_once()
Expand Down