我的公司有一个定制开发的 logger 包,我们希望将它用作 fastify 中的默认 logger。我试图通过下面这个简单的示例来了解如何注册我的记录器,但 fastify 总是使用 Pino。
index.js
const log = require("./Logger");
const fastify = require("fastify")({ logger: log });
fastify.get("/", (request, reply) => {
request.log(
"includes request information, but is the same logger instance as `log`"
);
reply.send({ hello: "world" });
});
fastify.listen(3000)
logger.js
function Logger(...args) {
this.args = args;
}
Logger.prototype.info = function(msg) {
console.log("myLogger", msg);
};
logger.js
还包含error
, debug
, fatal
, warn
, trace
,child
函数,但函数体是相同的。
结果是:
{"level":30,"time":1553095994942,"msg":"Server listening at http://127.0.0.1:3000","pid":14543,"hostname":"VirtualBox","v":1}
whitch 是默认的 Pino 输出。