File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Version: Used in the /about endpoint. Useful to expose the Docker image version.
2+ # LOG_FORMAT=pretty
23# LOG_LEVEL=info
34# VESION=1.0.0
45
Original file line number Diff line number Diff line change @@ -2,16 +2,25 @@ import pino from 'pino';
22
33export type Logger = pino . Logger ;
44
5- const loggerConfigEnv =
6- process . env . NODE_ENV === 'production'
7- ? { }
8- : {
5+ function getLogger ( ) {
6+ // Uses pretty print if env.LOG_FORMAT is set to 'pretty'. By default, it will also use it for non-production environments.
7+ // If the env.LOG_FORMAT is not 'pretty', it defaults to a JSON logger.
8+ const usePrettyPrint = process . env . LOG_FORMAT
9+ ? process . env . LOG_FORMAT === 'pretty'
10+ : process . env . NODE_ENV !== 'production' ;
11+
12+ const loggerConfigEnv = usePrettyPrint
13+ ? {
914 transport : {
1015 target : 'pino-pretty' ,
1116 } ,
12- } ;
17+ }
18+ : { } ;
19+
20+ return pino ( {
21+ ...loggerConfigEnv ,
22+ level : process . env . LOG_LEVEL ?? 'info' ,
23+ } ) ;
24+ }
1325
14- export const logger = pino ( {
15- ...loggerConfigEnv ,
16- level : process . env . LOG_LEVEL ?? 'info' ,
17- } ) ;
26+ export const logger = getLogger ( ) ;
You can’t perform that action at this time.
0 commit comments