Cloud logging
This cloud logging package is an interface for @google-cloud/logging.
Once initialized, you might use it as simple as: log.info("order processed", {orderId: "1209235823"});
.
The first argument is the message, the second argument is an object to create log labels with. Those labels are very helpfull in order to filter you log messages afterwards. You'd better use them!
Install
npm i @code-nl/cloud-logging --save
Usage
In order to make use of the cloud logging, you need to initialize the logger.
It takes 2 arguments:
- Google Cloud project id
- Log name which is the grouper
const log = require("@code-nl/cloud-logging");
// initialize with:
// project id: "my-gcp-project-id"
// log name: "some-log-name"
log.init("my-gcp-project-id", "some-log-name");
// create a log message with severity "info"
log.info("My log message with useful context", {id: "1234", test: "ABC"});