From 2a75d244f734e178e0026f0d03033b7d913112cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20Roli=C5=84ski?= Date: Wed, 10 Dec 2025 12:25:52 +0100 Subject: [PATCH 1/2] Unbind `Logger` from `module` type It can take a string, a module, or anything with an `id` now. --- packages/utils/src/Logger.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/utils/src/Logger.ts b/packages/utils/src/Logger.ts index 3b4e89e477..e46d72d0f8 100644 --- a/packages/utils/src/Logger.ts +++ b/packages/utils/src/Logger.ts @@ -72,6 +72,8 @@ function wrappedMethodCall( } } +type Scope = string | { id: string } + export class Logger { static NAME_LENGTH = 25 @@ -84,13 +86,13 @@ export class Logger { trace: (msg: string, metadata?: Record) => void constructor( - module: NodeJS.Module, + scope: Scope, contextBindings?: Record, defaultLogLevel: LogLevel = 'info', parentLogger: pino.Logger = rootLogger ) { this.logger = parentLogger.child({ - name: Logger.createName(module), + name: Logger.createName(scope), ...contextBindings }, { level: process.env.LOG_LEVEL ?? defaultLogLevel @@ -103,8 +105,9 @@ export class Logger { this.trace = wrappedMethodCall(this.logger.trace.bind(this.logger)) } - static createName(module: NodeJS.Module): string { - const parsedPath = path.parse(String(module.id)) + static createName(scope: Scope): string { + const scopeId = typeof scope === 'string' ? scope : scope.id + const parsedPath = path.parse(scopeId) let fileId = parsedPath.name if (fileId === 'index') { // file with name "foobar/index.ts" -> "foobar" From ba0369c3e5ebe898149592aaa664e755fdb6f54a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20Roli=C5=84ski?= Date: Wed, 10 Dec 2025 13:26:54 +0100 Subject: [PATCH 2/2] =?UTF-8?q?`Scope`=20=E2=86=92=20`LoggerModule`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/utils/src/Logger.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/utils/src/Logger.ts b/packages/utils/src/Logger.ts index e46d72d0f8..e7ab7f432a 100644 --- a/packages/utils/src/Logger.ts +++ b/packages/utils/src/Logger.ts @@ -72,7 +72,7 @@ function wrappedMethodCall( } } -type Scope = string | { id: string } +type LoggerModule = string | { id: string } export class Logger { static NAME_LENGTH = 25 @@ -86,13 +86,13 @@ export class Logger { trace: (msg: string, metadata?: Record) => void constructor( - scope: Scope, + loggerModule: LoggerModule, contextBindings?: Record, defaultLogLevel: LogLevel = 'info', parentLogger: pino.Logger = rootLogger ) { this.logger = parentLogger.child({ - name: Logger.createName(scope), + name: Logger.createName(loggerModule), ...contextBindings }, { level: process.env.LOG_LEVEL ?? defaultLogLevel @@ -105,9 +105,9 @@ export class Logger { this.trace = wrappedMethodCall(this.logger.trace.bind(this.logger)) } - static createName(scope: Scope): string { - const scopeId = typeof scope === 'string' ? scope : scope.id - const parsedPath = path.parse(scopeId) + static createName(loggerModule: LoggerModule): string { + const loggerModuleId = typeof loggerModule === 'string' ? loggerModule : loggerModule.id + const parsedPath = path.parse(loggerModuleId) let fileId = parsedPath.name if (fileId === 'index') { // file with name "foobar/index.ts" -> "foobar"