bada-terminal / src /utils /debug-log.js
VanyaJ's picture
Release BADA Terminal v2.1.0 (Enterprise Ontology, NVIDIA auto-ontology, Release Preflight)
d739b1b verified
Raw History Blame Contribute Delete
1.35 kB
const fs = require('fs');
const path = require('path');
let CLAUDE_DIR = null;
let isRotating = false;
function setClaudeDir(dir) {
CLAUDE_DIR = dir;
}
async function writeDebugLog(msg) {
try {
if (!CLAUDE_DIR) {
const os = require('os');
CLAUDE_DIR = path.join(os.homedir(), '.claude');
}
const logPath = path.join(CLAUDE_DIR, 'desktop-cli-debug.log');
// ํŒŒ์ผ ๋กœํ…Œ์ด์…˜ (๋น„๋™๊ธฐ๋กœ ์‹คํ–‰ํ•˜๋˜, ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์ง„ํ–‰ํ•˜์—ฌ ๋ฉ”์ธ ๋ฃจํ”„ ๋ธ”๋กœํ‚น ๋ฐฉ์ง€)
if (!isRotating) {
isRotating = true;
fs.promises.stat(logPath).then(async (stat) => {
if (stat.size > 5 * 1024 * 1024) {
try {
const content = await fs.promises.readFile(logPath, 'utf-8');
const lines = content.split('\n');
await fs.promises.writeFile(logPath, lines.slice(-1000).join('\n'), 'utf-8');
} catch (err) {
console.error('[Logger] Rotation error:', err.message);
}
}
isRotating = false;
}).catch(() => {
isRotating = false;
});
}
const time = new Date().toISOString();
await fs.promises.appendFile(logPath, `[${time}] ${msg}\n`, 'utf-8');
} catch (e) {
console.warn('[Logger] Fallback debug log:', msg);
}
}
module.exports = {
setClaudeDir,
writeDebugLog
};