Logging with Winston in Logtail

Install the @logtail/winston NPM package and set up the Logtail transport according to the following example

npm install @logtail/winston
npm install @logtail/node
Copied!
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)],
});

// Log as normal in Winston - your logs will sync with Logtail.com!
logger.log({
  level: "info", // <-- will use Logtail's `info` log level,
  message: "Some message", // <-- will also be passed to Logtail
});
Copied!
warning

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