Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2026. It is now read-only.
This repository was archived by the owner on Feb 26, 2026. It is now read-only.

Structured Logging Handler should be project aware #544

Copy link
Copy link

Description

@averikitsch
Issue body actions

I want to use StructuredLogHandler directly to ensure printing to stdout regardless of location, especially locally. I want my project Id to be automatically inferred so the trace ID includes my project ID ("logging.googleapis.com/trace": "projects/PROJECT_ID/traces/abcdef",).

Neither locally or remotely, will the project id be set automatically:

    logging_client = Client()
    from google.cloud.logging_v2.handlers import StructuredLogHandler, setup_logging
    handler = StructuredLogHandler()
    setup_logging(handler)

    import logging

    msg = "Hello, world!"
    metadata = {"component": "arbitrary-property", "severity":"error"}
    logging.info(msg, extra={"json_fields": metadata})

The solution is to set the project ID:

handler = StructuredLogHandler(project_id="PROJECT_ID")
setup_logging(handler)

Or use CloudLoggingHandler (note this doesn't print to stdout unless env vars are set):

logging_client = Client()
logging_client.setup_logging()
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    2023-triageapi: loggingIssues related to the googleapis/python-logging API.Issues related to the googleapis/python-logging API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.