From c89bf8e4101a22ea3cd87798504330e129322dd4 Mon Sep 17 00:00:00 2001 From: "Max P." Date: Sat, 11 Oct 2025 13:56:20 +0200 Subject: [PATCH] feat(logger): add current working directory handling --- lib/logger.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/logger.ts b/lib/logger.ts index be97fbc..dd38d5e 100644 --- a/lib/logger.ts +++ b/lib/logger.ts @@ -172,6 +172,21 @@ function getPid(): number { return (globalThis as CrossPlatformGlobal).process?.pid || 0; } +function getCwd(): string { + try { + if (runtime.isDeno) return Deno.cwd(); + if (runtime.isNode || runtime.isBun) { + const requireFn = (globalThis as CrossPlatformGlobal).require || + eval("require"); + const proc = requireFn("process"); + return proc?.cwd?.() ?? requireFn("path")?.resolve?.() ?? "."; + } + } catch { + // ignore + } + return "."; +} + function getHostname(): string { if (runtime.isDeno) { return Deno.hostname(); @@ -571,7 +586,9 @@ class Logger { simpleFormatter(logEntry: LogEntry): string { const levelPadded = logEntry.level.toUpperCase().padEnd(5); const caller = logEntry.callerFile - ? `${logEntry.callerFile.split("/").pop()}:${logEntry.callerLine}` + ? `${ + logEntry.callerFile.replace(getCwd() + "/", "") + }:${logEntry.callerLine}` : null; return caller