The library exposes a function to write directly to DataDog from your own application. The example below shows how this can be done using pino-multi-stream.
Example:
const datadog = require('pino-datadog')
const pinoms = require('pino-multi-stream')
// create the datadog destination stream
const writeStream = await datadog.createWriteStream()
// create pino logger
const logger = pinoms({ streams: [{ stream: 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.
*This function is async because of compatibility reasons
Example:
const writeStream = await datadog.createWriteStream({
apiKey: 'blablabla',
size: 10
})
The createWriteStreamSync
function creates a writestream that pino-multi-stream
can use to send logs to.
Example:
const writeStream = datadog.createWriteStreamSync({ apiKey: 'blablabla', size: 10 })
Type: String
(required)
The API key that can be found in your DataDog account (Integration > APIs).
Type: String
(optional)
The number of log messages to send as a single batch (defaults to 1).
Type: String
(optional)
Set a default source to all the logs sent to datadog
Type: String
(optional)
Set a default list of tags for all the logs sent to datadog
Type: String
(optional)
Set a default service to all the logs sent to datadog
Type: String
(optional)
Set a default hostname to all the logs sent to datadog
Type: Boolean
(optional)
Keep the msg
attribute in the log record. Used to allow a Datadog facet on the message.