googleapis / nodejs-logging

Node.js client for Stackdriver Logging: Store, search, analyze, monitor, and alert on log data and events from Google Cloud Platform and Amazon Web Services (AWS).
https://cloud.google.com/logging/
Apache License 2.0
172 stars 62 forks source link

Does the Logging client support logs and Entries for Folders and Organizations #1398

Open smilinazzo opened 1 year ago

smilinazzo commented 1 year ago

Hey,

I'm looking for some clarification and direction. I currently have some resources setup as follows:

─ my-organization
    └── my-folder
          └── my-project

I can write logs to a project with the sample code:

async write(): {
  const logging = new Logging();
  const log = logging.log('folder-log-1');

  // A json log entry with additional context
  const metadata = {
    severity: 'WARNING',
    resource: {
      type: 'global'
    }
  };

  const message = {
    "message": "Some message for some log",
  };

  const json_Entry = log.entry(metadata, message);
  await log.write(json_Entry);
}

But, I would also like to write/retrieve logs/entries from the organization and folder levels. The service account for the project has Logging Admin and Logs Viewer access for the Folder and organization.

Is this client only able to write/view logs and entries for a Project?

losalex commented 1 year ago

Thanks @smilinazzo for opening this issue. Looking into formatLogName, it seems we do not support folder/organizations as defined in logName. I will turn this issue into a feature as well.

smilinazzo commented 1 year ago

Thank @losalex.

I was able to get what I needed by doing:

  async getLogs(resource: 'projects' | 'folders' | 'organizations'): Promise<string[]> {
    const response = await this._client.auth.request({
      url: `https://logging.googleapis.com/v2/${resource}/logs`,
      method: 'GET'
    });

    return response.data;
  }

But being able to use the client directly would be great.