0.0.4 • Published 3 years ago

@mpodsiadlo/gcp-logger v0.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

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:

GCP Log

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
);

More info on the Twilio website

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago