Skip to content

Commit

Permalink
feat: prettify logger in development mode
Browse files Browse the repository at this point in the history
  • Loading branch information
valnyx17 committed May 10, 2024
1 parent d107fff commit 075edcd
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
87 changes: 87 additions & 0 deletions api/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 api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"eslint": "^8.57.0",
"globals": "^15.2.0",
"nodemon": "^3.0.3",
"pino-pretty": "^11.0.0",
"prettier": "^3.2.5",
"prisma": "^5.13.0",
"typescript": "^5.3.3",
Expand Down
16 changes: 15 additions & 1 deletion api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,22 @@ const serverOptions: ServerOptions = {
const sessionTokens: Record<number, SessionToken[]> = {};
const backends: Record<number, BackendBaseClass> = {};

const loggerEnv = {
development: {
transport: {
target: 'pino-pretty',
options: {
translateTime: 'HH:MM:ss Z',
ignore: 'pid,hostname,time',
},
},
},
production: true,
test: false,
}

const fastify = Fastify({
logger: true,
logger: (process.env.NODE_ENV != "production" ? loggerEnv.development : loggerEnv.production),
trustProxy: Boolean(process.env.IS_BEHIND_PROXY),
});

Expand Down

0 comments on commit 075edcd

Please sign in to comment.