Stackdriver target + formatter for Bristol
This package provides a Bristol target + formatter that sends logs to Google Cloud Stackdriver.
Install
With npm
:
npm install bristol-stackdriver
Or with yarn
yarn add bristol-stackdriver
Usage
Import the target
and formatter
and add them to your Bristol instance.
const logger = logger loggerlogger
API
bristol-stackdriver
has a few tricks up its' sleeve. The examples only present relevant configuration changes for brevity.
Custom severities
Bristol allows you to customize your severities. The Stackdriver target needs to know how to map them to Stackdriver-specific severities.
You are not required to use/map them all, but those which are not mapped will be logged as DEFAULT
.
loggerlogger // Gets logged to Stackdriver as `EMERGENCY`.logger
Adding labels to log entries
Stackdriver supports labels. To add labels to your log messages, use the sd:labels
field when logging.
loggerlogger logger
Stackdriver Error Reporting
Reporting errors toIf you configure the target with a serviceContext
, whenever an Error
gets logged Stackdriver will automatically send it to Error Reporting.
logger logger
user
and httpContext
for Error Reporting
Attaching Error Reporting can show request/response information about an error, as well as the ID of the user.
In order for the transport to submit that info, you need to attach it using sd:req
, sd:res
(or sd:httpContext
) and sd:user
.
http
Alternatively, if you want to specify the HTTP context yourself.
http
In fact, using sd:req
and sd:res
is the exact same as doing:
logger
Callbacks when flushing to Stackdriver (fails)
If you want to (for whatever reason) know when the target flushes to Stackdriver—or when it fails—you can attach some callbacks.
logger
Contributing
You will need a Google Cloud Project ID + keyfile to run the tests!
You can either add the project ID + keyfile (JSON stringified) to your own environment (GCLOUD_PROJECT=your-project-id GCLOUD_CREDENTIALS="{\"type\": \"...\"}"
), or you can create an env.yaml
in the repository root, and add the following:
test: GCLOUD_PROJECT: your-project-id GCLOUD_CREDENTIALS: > { "type": "...", <..remaining key...> }
Authors
Taxfyle Engineering — @taxfyle
Or, more specifically, this handsome devil. This is the guy to complain to if stuff isn't working.