Skip to content

Commit

Permalink
sample custom log infos
Browse files Browse the repository at this point in the history
  • Loading branch information
leandroandrade committed Mar 21, 2024
1 parent b774727 commit afd1ab9
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions custom-log-infos/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const Fastify = require('fastify');

(async () => {
const app = Fastify({
logger: {
level: 'info',
serializers: {
req: (request) => ({
method: request.raw.method,
url: request.raw.url,
hostname: request.hostname,
}),
res: (response) => ({
statusCode: response.statusCode,
}),
},
},
});

app.get('/', async (req, res) => {
return { hello: 'world' };
});

await app.listen({ port: 3000 });
})();

// curl -H 'x-log-level: error' http://localhost:3000

0 comments on commit afd1ab9

Please sign in to comment.