Skip to content
This repository was archived by the owner on Aug 13, 2026. It is now read-only.
This repository was archived by the owner on Aug 13, 2026. It is now read-only.

Allowing filtering/formatting of Stackdriver logs #17

Closed

Description

@joshburkart

Hello,

I'm using the instructions here to send Python logging module logs to Stackdriver. Thanks for making this so easy! However, doing this naively seems to make all logs from potentially many jobs/VMs/etc. get merged together in the Stackdriver UI. When I filter to e.g. a specific VM, none of the logs show up (screenshot) -- I have to set the filtering to "Global" to see them (screenshot). Am I doing something wrong?

Also, what about logging things like files, line numbers, etc.? Is this possible? Does Stackdriver respect formatting I apply using the Python logging API? What about automatic links to files in connected code repos etc. -- any info available on that?

Thanks!

Activity

  1. tseaver commented on Mar 16, 2018

    @tseaver
    Contributor

    @liyanhui1228 Can you point @joshburkart in the right direction?

  2. joshburkart commented on Mar 20, 2018

    @joshburkart
    Author

    I figured this out (I think) -- I now make calls to the metadata endpoint to determine info about the current VM, then pass these as labels when making logging handlers. Rough code snippet in case it's useful to someone:

    import logging as pylogging
    
    from google.cloud import logging as cloudlogging
    
    ...
    
    handler = cloudlogging.handlers.CloudLoggingHandler(
        <stackdriver_client>,
        resource=cloudlogging.resource.Resource(
            # See e.g. https://cloud.google.com/monitoring/api/resources
            # for more info on codified Stackdriver "Resources".
            type='gce_instance',
            labels=<gce_instance labels retrieved from metadata endpoint>,
        ),
        labels=<any extra labels>,
    )
    
    logger = pylogging.getLogger('whatever')
    logger.addHandler(handler)

    (I think this should be added to the documentation or something, though...)

  3. tseaver commented on Mar 26, 2018

    @tseaver
    Contributor

    @liyanhui1228 I'm not sure where such an example should go: who manages the snippets / examples used in the cloud.google.com docs?

  4. tseaver commented on Oct 18, 2018

    @tseaver
    Contributor

    @dazuma Can you help direct this to the right target for updating the API docs?

  5. tseaver commented on Dec 5, 2018

    @tseaver
    Contributor

    @JustinBeckwith, @theacodes can either of you point me to the person / team responsible for managing the cloud.google.com/logging docs samples?

  6. added this to the v2.4.0 milestone on Feb 4, 2021
  7. self-assigned this
    on Feb 5, 2021
  8. added
    priority: p3Desirable enhancement or fix. May not be included in next release.
    on Feb 5, 2021
  9. daniel-sanche commented on Mar 5, 2021

    @daniel-sanche
    Contributor

    As of #200, the resource should be auto-detected for each GCP environment. It sounds like that was the ask for this issue, so I'll close this. Feel free to re-open if there are any remaining concerns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: loggingIssues related to the googleapis/python-logging API.backendpriority: p3Desirable enhancement or fix. May not be included in next release.type: docsImprovement to the documentation for an API.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions