Closed eloisetaylor5693 closed 7 months ago
You might not need a fork for this. The library supports a logger
parameter in it's config. If this is set, and a function, it will be called instead of any Pino instantiation.
For example:
// next-logger.config.js
const { createLogger } = require('winston')
const defaultWinstonConfig = require('./defaultWinstonConfig')
const logger = () => createLogger(defaultWinstonConfig)
module.exports = {
logger,
}
Hi @atkinchris, that sounds exactly what I'm looking for. I tried it out on a create next app demo website and got the following error:
yarn dev
yarn run v1.22.21
$ NODE_OPTIONS='-r next-logger' next dev
C:\code\nextjs-starters\my-nextjs-app\node_modules\next-logger\lib\patches\next.js:14
return childLogger.trace.bind(childLogger)
^
TypeError: Cannot read properties of undefined (reading 'bind')
at getPinoMethod (C:\code\nextjs-starters\my-nextjs-app\node_modules\next-logger\lib\patches\next.js:14:32)
at C:\code\nextjs-starters\my-nextjs-app\node_modules\next-logger\lib\patches\next.js:21:24
at Array.forEach (<anonymous>)
at Object.<anonymous> (C:\code\nextjs-starters\my-nextjs-app\node_modules\next-logger\lib\patches\next.js:20:34)
at Module._compile (node:internal/modules/cjs/loader:1241:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12)
at Module.require (node:internal/modules/cjs/loader:1115:19)
at require (node:internal/modules/helpers:130:18)
Node.js v20.9.0
Note: This command was run via npm module 'win-node-env'
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Using this next-logger.config.js
const { createLogger, format, transports } = require("winston");
const logger = () =>
createLogger({
format: format.combine(
format.timestamp(),
format.simple(),
format.colorize()
),
defaultMeta: { type: "nextjs" },
transports: [
new transports.Console(),
new transports.File({ filename: "combined.log" }),
],
});
module.exports = {
logger,
};
This PR is not supposed to be merged into the original library. Pino is still useful, it's just in our codebase we use winston