
Winston version 3.2.1 or higher is required.
Install Logtail Winston and Logtail Node NPM packages:
npm install @logtail/winston @logtail/node
Set up Logtail Winston transport:
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)],
});
Use Winston logger as usual:
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.
Please let us know at hello@betterstack.com.
We're happy to help! ๐
Interested in learning more about using multiple Winston transports and Winston log levels? Check out our Complete Guide to Winston Logging in Node.js.
You may encounter TypeScript errors when including the transformer, which can be fixed by modifying the TypeScript config.
For a 'TransportStream'
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:
"moduleResolution": "node",
"esModuleInterop": true
Thanks @Nightbr for submitting this!