我正在尝试在 fastify 记录器选项上使用 prettyprint: true
,如下所示:
const build = require("./app");
const startServer = async () => {
try {
const app = await build({
logger: {
prettyPrint: true
},
});
const PORT = process.env.PORT;
await app.listen(PORT);
} catch (err) {
console.log(err);
process.exit(1);
}
};
startServer().catch();
pino-pretty
软件包已安装
当我尝试运行服务器时出现此错误:
const formatted = pretty(typeof redact === 'function' ? redact(obj) : obj)
^
TypeError: pretty is not a function
检查了这行代码(/node_modules/pino/lib/tools.js 282),pretty
类型是object
,但在代码中它被用作函数
const formatted = pretty(typeof redact === 'function' ? redact(obj) : obj)
有什么想法吗?
最佳答案
找到解决办法
安装
pino
和pino-pretty
软件包 (npm i pino pino-pretty
)通过要求
pino
并将pretty-print: true
添加到选项来初始化记录器
const build = require("./app");
const startServer = async () => {
try {
const app = await build({
logger: require("pino")({ prettyPrint: true }), // here
});
await app.listen(app.config.PORT);
} catch (err) {
console.log(err);
process.exit(1);
}
};
startServer().catch();
关于node.js - 漂亮没有在 fastify Pretty print 中定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69133907/