MCPcopy
hub / github.com/vercel/next.js / flush

Method flush

packages/next/src/server/dev/browser-logs/file-logger.ts:83–111  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

81 }
82
83 private flush(): void {
84 if (this.logQueue.length === 0) {
85 return
86 }
87
88 // Only flush to disk if mcpServer is enabled
89 if (!this.mcpServerEnabled) {
90 this.logQueue.length = 0 // Clear the queue without GC overhead
91 this.flushTimer = null
92 return
93 }
94
95 try {
96 // Ensure the directory exists before writing
97 const logDir = path.dirname(this.logFilePath)
98 if (!fs.existsSync(logDir)) {
99 fs.mkdirSync(logDir, { recursive: true })
100 }
101
102 const logsToWrite = this.logQueue.join('')
103 // Writing logs to files synchronously to ensure they're written before returning
104 fs.appendFileSync(this.logFilePath, logsToWrite)
105 this.logQueue.length = 0 // Clear the queue without GC overhead
106 } catch (error) {
107 console.error('Failed to flush logs to file:', error)
108 } finally {
109 this.flushTimer = null
110 }
111 }
112
113 private enqueueLog(formattedEntry: string): void {
114 this.logQueue.push(formattedEntry)

Callers 6

scheduleFlushMethod · 0.95
forceFlushMethod · 0.95
renderToHTMLImplFunction · 0.45
styledJsxInsertedHTMLFunction · 0.45
renderDocumentFunction · 0.45
createWriterFromResponseFunction · 0.45

Calls 2

errorMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected