feat: AI日志文件写入文件原始路径

This commit is contained in:
digua
2026-04-14 20:41:30 +08:00
committed by digua
parent f20553d5c7
commit 65923982ac
+13
View File
@@ -22,6 +22,15 @@ let LOG_DIR: string | null = null
let LOG_FILE: string | null = null
let logStream: fs.WriteStream | null = null
function formatPathForLog(filePath: string): string {
return filePath.replace(/ /g, '\\ ')
}
function writeLogFileHeader(stream: fs.WriteStream, filePath: string): void {
const localPath = formatPathForLog(filePath)
stream.write(`Local Path: ${localPath}\n\n`)
}
/**
* 获取日志目录
*/
@@ -75,7 +84,11 @@ function getLogStream(): fs.WriteStream {
if (logStream) return logStream
const filePath = getLogFilePath()
const isNewOrEmptyFile = !fs.existsSync(filePath) || fs.statSync(filePath).size === 0
logStream = fs.createWriteStream(filePath, { flags: 'a', encoding: 'utf-8' })
if (isNewOrEmptyFile) {
writeLogFileHeader(logStream, filePath)
}
return logStream
}