MCPcopy
hub / github.com/liuup/claude-code-analysis / getDebugWriter

Function getDebugWriter

src/utils/debug.ts:155–196  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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