Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Commit

Permalink
fix(logs): pretty print logs in development to close #3
Browse files Browse the repository at this point in the history
  • Loading branch information
nahtnam committed May 1, 2019
1 parent 0f968da commit cbcec7a
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 6 deletions.
90 changes: 87 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"micro-http-router": "^1.3.0",
"micromatch": "^4.0.1",
"pino-http": "^4.2.0",
"pino-pretty": "^3.0.0",
"yargs": "^13.2.2"
},
"devDependencies": {
Expand Down
11 changes: 8 additions & 3 deletions src/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ export default (route: Route): Handler => {
const middleware: any[] = route.middleware || [];

if (fn.log !== false) {
const logger = pino();
const pinoOptions = process.env.NODE_ENV === 'production' ? {} : {
prettyPrint: {
levelFirst: true,
},
};
const logger = pino(pinoOptions);
middleware.unshift(logger);
}

for (const mw of middleware) { // eslint-disable-line
await mw(req, res); // eslint-disable-line
for (const mw of middleware) { // eslint-disable-line
await mw(req, res); // eslint-disable-line
}

return route.handler(req, res);
Expand Down

0 comments on commit cbcec7a

Please sign in to comment.