api: ditch pino pretty for non-dev environments
Parents:
6559a001 file(s) changed
- api/src/createApp.ts +11 -8
api/src/createApp.ts
1 1
import express from 'express';
2 2
import cors from 'cors';
3 3
import bodyParser from 'body-parser';
4 4
import morgan from 'morgan';
5 5
import mainRouter from '@app/routes/main';
▸ 19 unchanged lines
25 25
credentials: true
26 26
}));
27 27
28 28
app.use(bodyParser.json());
29 29
30 -
// Create Pino logger
30 +
const isDev = process.env.NODE_ENV !== 'production';
31 +
31 32
const logger = pino({
32 33
level: process.env.LOG_LEVEL || 'info',
33 -
transport: {
34 -
target: 'pino-pretty', // Human-readable in development
35 -
options: {
36 -
colorize: true,
37 -
singleLine: false,
38 -
messageFormat: '{if levelLabel}{levelLabel} - {end}{msg}',
34 +
...(isDev && {
35 +
transport: {
36 +
target: 'pino-pretty',
37 +
options: {
38 +
colorize: true,
39 +
singleLine: false,
40 +
messageFormat: '{if levelLabel}{levelLabel} - {end}{msg}',
41 +
},
39 42
},
40 -
},
43 +
}),
41 44
});
42 45
43 46
// Use pino-http for HTTP logging (better than Morgan for structured logs)
44 47
app.use(pinoHttp({ logger }));
45 48
▸ 18 unchanged lines
64 67
65 68
const shutdown = async () => {
66 69
await Promise.all([closeAllWorkers(), closeAllQueues()]);
67 70
process.exit(0);
68 71
};