feat(logger): add current working directory handling
This commit is contained in:
@@ -172,6 +172,21 @@ function getPid(): number {
|
|||||||
return (globalThis as CrossPlatformGlobal).process?.pid || 0;
|
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 {
|
function getHostname(): string {
|
||||||
if (runtime.isDeno) {
|
if (runtime.isDeno) {
|
||||||
return Deno.hostname();
|
return Deno.hostname();
|
||||||
@@ -571,7 +586,9 @@ class Logger {
|
|||||||
simpleFormatter(logEntry: LogEntry): string {
|
simpleFormatter(logEntry: LogEntry): string {
|
||||||
const levelPadded = logEntry.level.toUpperCase().padEnd(5);
|
const levelPadded = logEntry.level.toUpperCase().padEnd(5);
|
||||||
const caller = logEntry.callerFile
|
const caller = logEntry.callerFile
|
||||||
? `${logEntry.callerFile.split("/").pop()}:${logEntry.callerLine}`
|
? `${
|
||||||
|
logEntry.callerFile.replace(getCwd() + "/", "")
|
||||||
|
}:${logEntry.callerLine}`
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
return caller
|
return caller
|
||||||
|
|||||||
Reference in New Issue
Block a user