Better Stack Winston transport

Start logging in 3 steps

1. Install

Install Logtail Winston and Logtail Node NPM packages:

Install Logtail packages
npm install @logtail/winston @logtail/node

2. Setup

Set up Logtail Winston transport:

Set up Winston logger
const winston = require("winston");
const { Logtail } = require("@logtail/node");
const { LogtailTransport } = require("@logtail/winston");

// Create a Logtail client
const logtail = new Logtail("$SOURCE_TOKEN");

// Create a Winston logger - passing in the Logtail transport
const logger = winston.createLogger({
  transports: [new LogtailTransport(logtail)],
});

3. Start logging 🎉

Use Winston logger as usual:

Send logs to Logtail
logger.error("Something bad happened.");
logger.info("Log message with structured logging.", {
  item: "Orange Soda",
  price: 100.00
});

// Ensure that all logs are sent to Logtail
logtail.flush()

You should see your logs in Logtail → Live tail.

Winston version 3.2.1 or higher is required.

Need help?

Please let us know at hello@betterstack.com.
We're happy to help! 🙏

Additional resources

Interested in learning more about using multiple Winston transports and Winston log levels? Check out our Complete Guide to Winston Logging in Node.js.

Common issues

TypeScript error during import

You may encounter TypeScript errors when including the transformer, which can be fixed by modifying the TypeScript config.

For a 'TransportStream' error:

TypeScript error
Argument of type 'LogtailTransport' is not assignable to parameter of type 'TransportStream'.
  Type 'LogtailTransport' is missing the following properties from type 'TransportStream': writable, writableEnded, writableFinished, writableHighWaterMark, and 29 more.

Modify tsconfig.json with:

TS config
  "moduleResolution": "node",
  "esModuleInterop": true

Thanks @Nightbr for submitting this!