nodejs-logging icon indicating copy to clipboard operation
nodejs-logging copied to clipboard

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

Open smilinazzo opened this issue 3 years ago • 2 comments

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?

smilinazzo avatar Jan 04 '23 18:01 smilinazzo

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.

losalex avatar Jan 05 '23 17:01 losalex

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.

smilinazzo avatar Jan 06 '23 17:01 smilinazzo