The library exposes a function to write directly to Stackdriver from your own application. The example below shows how this can be done using pino-multi-stream.
Example:
const stackdriver = require('pino-stackdriver')
const pinoms = require('pino-multi-stream')
// create the stackdriver destination stream
const credentials = '/credentials.json'
const projectId = 'my-project'
const writeStream = stackdriver.createWriteStream({ credentials, projectId })
// create pino loggger
const logger = pinoms({ streams: [writeStream] })
// log some events
logger.info('Informational message')
logger.error(new Error('things got bad'), 'error message')The createWriteStream function creates a writestream that pino-multi-stream can use to send logs to.
Example:
const writeStream = stackdriver.createWriteStream({
credentials: '/credentials.json',
projectId: 'my-project'
})Type: String (optional)
Full path to the JSON file containing the Google Service Credentials. Defaults to the GOOGLE_APPLICATION_CREDENTIALS environment variable. At least one has to be available.
Type: String (required)
The name of the project.
Type: String (optional)
The name of the log. Defaults to "pino_log".
Type: { type: String, labels: Object } (optional)
The resource to send logs to. Defaults to { type: "global" }.
Type: { [key]: key } (optional)
Customize additional fields to pull from log messages and include in meta. Currently
supports httpRequest, trace. Defaults to { httpRequest: "httpRequest" }.