MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / getDebugWriter

Function getDebugWriter

source code/utils/debug.ts:157–198  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

155function noop(): void {}
156
157function getDebugWriter(): BufferedWriter {
158 if (!debugWriter) {
159 let ensuredDir: string | null = null
160 debugWriter = createBufferedWriter({
161 writeFn: content => {
162 const path = getDebugLogPath()
163 const dir = dirname(path)
164 const needMkdir = ensuredDir !== dir
165 ensuredDir = dir
166 if (isDebugMode()) {
167 // immediateMode: must stay sync. Async writes are lost on direct
168 // process.exit() and keep the event loop alive in beforeExit
169 // handlers (infinite loop with Perfetto tracing). See #22257.
170 if (needMkdir) {
171 try {
172 getFsImplementation().mkdirSync(dir)
173 } catch {
174 // Directory already exists
175 }
176 }
177 getFsImplementation().appendFileSync(path, content)
178 void updateLatestDebugLogSymlink()
179 return
180 }
181 // Buffered path (ants without --debug): flushes ~1/sec so chain
182 // depth stays ~1. .bind over a closure so only the bound args are
183 // retained, not this scope.
184 pendingWrite = pendingWrite
185 .then(appendAsync.bind(null, needMkdir, dir, path, content))
186 .catch(noop)
187 },
188 flushIntervalMs: 1000,
189 maxBufferSize: 100,
190 immediateMode: isDebugMode(),
191 })
192 registerCleanup(async () => {
193 debugWriter?.dispose()
194 await pendingWrite
195 })
196 }
197 return debugWriter
198}
199
200export async function flushDebugLogs(): Promise<void> {
201 debugWriter?.flush()

Callers 1

logForDebuggingFunction · 0.85

Calls 4

createBufferedWriterFunction · 0.85
getDebugLogPathFunction · 0.85
getFsImplementationFunction · 0.85
registerCleanupFunction · 0.85

Tested by

no test coverage detected