DADI Logger is an easy to use yet powerful logging service for use with Node.js services. It’s used by DADI Web, API, CDN, Publish, and Queue to provide extensible activity, access, and diagnostic logging.

You can use it as a standalone service:

const logger = require('@dadi/logger') logger.init({

enabled: true,

level: 'info',

path: './log',

filename: 'example_log',

extension: 'log'

}) logger.info('this is a log message')

Or you can use it as middleware:

const logger = require('@dadi/logger')

const express = require('express')

const app = express() logger.init(logConfig) app.use(logger.requestLogger)

Streams

Today I’d like to introduce you to a new feature we’ve added in version 1.3.0 — streams. Sometimes logging to files isn’t the best solution, for example when running a service inside a container, logging to stdout is better.

const logger = require('@dadi/logger') logger.init({

enabled: true,

level: 'info',

stream: process.stdout

}) logger.info('hello stdout')

But it gets better. As DADI Logger uses Bunyan under the hood, any library built for Bunyan streams will work. Let’s take a look at setting up bunyan-slack to send your logs to a Slack channel.

const logger = require('@dadi/logger')

const BunyanSlack = require('bunyan-slack') logger.init({

enabled: true,

level: 'info',

stream: new BunyanSlack({

webhook_url: "your_webhook_url",

channel: "#your_channel",

username: "your_username",

})

}) logger.info('hello Slack!')

It really is as easy as that.

If you have any ideas on how DADI Logger could be used, please let us know.