File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
src/infrastructure/logging Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -17,11 +17,19 @@ const loggerConfig = process.env['NODE_ENV'] === 'production'
1717
1818const rootLogger = pino ( loggerConfig ) ;
1919
20+ let loggerCache = new Map < keyof LoggingConfig , pino . Logger > ( ) ;
21+
2022/**
2123 * Creates child logger and returns it.
2224 * @param moduleName - name of the module that is logging
2325 */
2426export function getLogger ( moduleName : keyof LoggingConfig ) : pino . Logger {
27+ const cachedLogger = loggerCache . get ( moduleName ) ;
28+
29+ if ( cachedLogger ) {
30+ return cachedLogger ;
31+ }
32+
2533 const childLogger = rootLogger . child ( {
2634 module : moduleName ,
2735 } ) ;
@@ -34,6 +42,8 @@ export function getLogger(moduleName: keyof LoggingConfig): pino.Logger {
3442
3543 childLogger . level = logLevel ;
3644
45+ loggerCache . set ( moduleName , childLogger ) ;
46+
3747 return childLogger ;
3848}
3949
You can’t perform that action at this time.
0 commit comments