Skip to content

Latest commit

 

History

History
58 lines (38 loc) · 1.47 KB

API.md

File metadata and controls

58 lines (38 loc) · 1.47 KB

API

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

Functions

createWriteStream

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'
})

credentials

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.

projectId

Type: String (required)

The name of the project.

logName

Type: String (optional)

The name of the log. Defaults to "pino_log".

resource

Type: { type: String, labels: Object } (optional)

The resource to send logs to. Defaults to { type: "global" }.