My company have a custom developed logger package, and we want to use that as default logger in fastify. I tried to understand how to register my logger with this simple example below, but fastify always use 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
also contains error
, debug
, fatal
, warn
, trace
, child
functions but the functions body is same.
The result is:
{"level":30,"time":1553095994942,"msg":"Server listening at http://127.0.0.1:3000","pid":14543,"hostname":"VirtualBox","v":1}
whitch is the default Pino output.