79138756

Date: 2024-10-29 19:59:05
Score: 0.5
Natty:
Report link

Nearly two years later I think I have figured out how one would begin to do this. Thanks to this answer demonstrating how to use the API via gcloud, I was able to cobble together something similar using the Node wrapper for the Logging API (FYI this relies on application default for authentication):

const { Logging } = require('@google-cloud/logging');

const projectId = '[PROJECT_ID]';
const buildId = '[BUILD_ID]';

const logging = new Logging({ projectId });

logging
  .tailEntries({
    resourceNames: [`projects/${projectId}`],
    log: 'cloudbuild',
    filter: `resource.labels.build_id="${buildId}"`
  })
  .on('data', (response) => {
    response.entries.forEach((entry) => console.log(entry.data));
  });

This uses the tailEntries method of the logging API. Surely there are improvements to be made over this; a first and obvious one is that the logs are not necessarily in order (more on that in the docs related to Log streaming, which also provide a similar example to the one above). However, it is good to know it is possible.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Tanner Stern