Skip to content
Merged
Changes from all commits
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
11 changes: 7 additions & 4 deletions packages/utils/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ function wrappedMethodCall(
}
}

type LoggerModule = string | { id: string }

export class Logger {
static NAME_LENGTH = 25

Expand All @@ -84,13 +86,13 @@ export class Logger {
trace: (msg: string, metadata?: Record<string, unknown>) => void

constructor(
module: NodeJS.Module,
loggerModule: LoggerModule,
contextBindings?: Record<string, unknown>,
defaultLogLevel: LogLevel = 'info',
parentLogger: pino.Logger = rootLogger
) {
this.logger = parentLogger.child({
name: Logger.createName(module),
name: Logger.createName(loggerModule),
...contextBindings
}, {
level: process.env.LOG_LEVEL ?? defaultLogLevel
Expand All @@ -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(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"
Expand Down