File size: 1,351 Bytes
d739b1b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 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
};
|