next-ts-logger
v0.1.4
Published
A structured logger for Next.js compatible with Pino and Winston
Readme
next-ts-logger
This acts as log interceptor for next.js applications. Compatible with Pino and Winston.
Motivation
I was using pino and wanted to have also get my Next.js application work with it. I stumpled upon next-logger, but it does not support TypeScript and started to get buggy with turbopack enabled, so I decided to create this package.
Installation
npm install next-ts-loggerInstall one of the supported loggers:
# Pino
npm install pino
# or Winston
npm install winstonUsage
Create an instrumentation.ts file in your Next.js project root (or src/ directory):
With Pino
// instrumentation.ts
import pino from "pino";
import { registerNextLogger } from "next-ts-logger";
export function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
const logger = pino();
registerNextLogger(logger);
}
}With Winston
// instrumentation.ts
import winston from "winston";
import { registerNextLogger } from "next-ts-logger";
export function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
const logger = winston.createLogger({
transports: [new winston.transports.Console()],
});
registerNextLogger(logger);
}
}