Logging with Bunyan in Logtail

Install the @logtail/bunyan NPM package and set up the Logtail stream according to the following example:

npm install @logtail/bunyan
npm install @logtail/node
Copied!
const bunyan = requrie("bunyan");
const { Logtail } = require("@logtail/node");
const { LogtailStream } = require("@logtail/bunyan");

// Create a Logtail client
const logtail = new Logtail("logtail-source-token");

// Create a Bunyan logger - passing in the Logtail stream
const logger = bunyan.createLogger({
  name: "Example logger",
  level: "debug",
  streams: [
    {
      stream: new LogtailStream(logtail),
    },
  ],
});

// Log as normal in Bunyan - your logs will be sent to Logtail.com
logger.info("Hello from Bunyan");
Copied!
warning

Don't forget to replace with your actual source token which you can find by going to your account -> sources -> edit.