| 45 | } |
| 46 | |
| 47 | private getCallerFile(skipFrames: number = 3): string { |
| 48 | const originalPrepareStackTrace = Error.prepareStackTrace |
| 49 | try { |
| 50 | const err = new Error() |
| 51 | Error.prepareStackTrace = (_, stack) => stack |
| 52 | const stack = err.stack as unknown as NodeJS.CallSite[] |
| 53 | Error.prepareStackTrace = originalPrepareStackTrace |
| 54 | |
| 55 | // Skip specified number of frames to get to actual caller |
| 56 | for (let i = skipFrames; i < stack.length; i++) { |
| 57 | const filename = stack[i]?.getFileName() |
| 58 | if (filename && !filename.includes("/logger.")) { |
| 59 | // Extract just the filename without path and extension |
| 60 | const match = filename.match(/([^/\\]+)\.[tj]s$/) |
| 61 | return match ? match[1] : filename |
| 62 | } |
| 63 | } |
| 64 | return "unknown" |
| 65 | } catch { |
| 66 | return "unknown" |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | private async write(level: string, component: string, message: string, data?: any) { |
| 71 | if (!this.enabled) return |