Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: add caching for getLogger
  • Loading branch information
7eliassen committed Mar 25, 2026
commit 8596447f1bdef4cd71259f26b6a74acb942a01fc
10 changes: 10 additions & 0 deletions src/infrastructure/logging/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ const loggerConfig = process.env['NODE_ENV'] === 'production'

const rootLogger = pino(loggerConfig);

let loggerCache = new Map<keyof LoggingConfig, pino.Logger>();
Comment thread
7eliassen marked this conversation as resolved.
Outdated

/**
* Creates child logger and returns it.
* @param moduleName - name of the module that is logging
*/
export function getLogger(moduleName: keyof LoggingConfig): pino.Logger {
const cachedLogger = loggerCache.get(moduleName);

if (cachedLogger) {
return cachedLogger;
}

const childLogger = rootLogger.child({
module: moduleName,
});
Expand All @@ -34,6 +42,8 @@ export function getLogger(moduleName: keyof LoggingConfig): pino.Logger {

childLogger.level = logLevel;

loggerCache.set(moduleName, childLogger);

return childLogger;
}

Expand Down
Loading