( path: string, content: string, existingBytes: number, )
| 62 | } |
| 63 | |
| 64 | function applyDebugLogBudget( |
| 65 | path: string, |
| 66 | content: string, |
| 67 | existingBytes: number, |
| 68 | ): string | null { |
| 69 | const maxBytes = getDebugLogMaxBytes() |
| 70 | const state = getDebugLogBudgetState(path) |
| 71 | if (!state.initialized) { |
| 72 | state.bytes = existingBytes |
| 73 | state.initialized = true |
| 74 | } |
| 75 | if (state.capped) { |
| 76 | return null |
| 77 | } |
| 78 | if (state.bytes + content.length <= maxBytes) { |
| 79 | state.bytes += content.length |
| 80 | return content |
| 81 | } |
| 82 | |
| 83 | let preserved = '' |
| 84 | const lines = content.match(/[^\n]*\n|[^\n]+/g) ?? [] |
| 85 | for (const line of lines) { |
| 86 | if (state.bytes + preserved.length + line.length > maxBytes) { |
| 87 | break |
| 88 | } |
| 89 | preserved += line |
| 90 | } |
| 91 | |
| 92 | state.capped = true |
| 93 | const sentinel = `${new Date().toISOString()} [WARN] ${DEBUG_LOG_CAP_SENTINEL} maxBytes=${maxBytes} path=${path}\n` |
| 94 | state.bytes += preserved.length + sentinel.length |
| 95 | return preserved + sentinel |
| 96 | } |
| 97 | |
| 98 | async function applyDebugLogBudgetAsync( |
| 99 | path: string, |
no test coverage detected