@mpodsiadlo/gcp-logger
v0.0.4
Published
GCP Logging Library for Twilio Serverless
Downloads
4
Readme
GCP Stackdriver Logging Library for Twilio Serverless
This is a simple wrapper for the official @google-cloud/logging npm package. Main use case - to be able to await GCP Stackdriver logging operations reliably in serverless environments (built for Twilio Serverless, should work anywhere), as those tend to break logging streams for official Winston / Bunyan wrappers.
Usage:
Instantiate the logger:
const { GcpLogger } = require('@mpodsiadlo/gcp-logger');
const logger = new GcpLogger(
'some-prefix',
{ someLabel: 'someText' },
gcpLogName,
filePathToTheGcpKeyFile
);
Log a debug message synchronously:
let someObject = {
prop1: 'test',
prop2: 'another test'
};
await logger.debug('Some message', someObject);
The resulting Stackdriver Log should look something like this:
Note on Twilio Serverless
When using this within a Twilio Serveless Function, you can poplate the constructor with values from the
const { GcpLogger } = require('@mpodsiadlo/gcp-logger');
const logger = new GcpLogger(
'some-prefix',
{ someLabel: 'someText' },
gcpLogName, // Usually the service domain, availabile in context.DOMAIN_NAME
filePathToTheGcpKeyFile // Would normally be stored as a private asset in your service, path can be accessed by Runtime.getAssets()['/gcp-keyfilename.json'].path
);