feat: 添加按日分割的日志记录(output/logs/YYYY-MM-DD.log)

This commit is contained in:
2026-05-14 23:21:16 +08:00
parent 1bac98e046
commit d8c60a3166
2 changed files with 29 additions and 2 deletions
+2
View File
@@ -25,6 +25,8 @@ CLI 自动完成:打开标签页 → 导航 → 粘贴参考图 → 输入提
生图完成后将图片移到目标位置,通过 `message` 工具发送。 生图完成后将图片移到目标位置,通过 `message` 工具发送。
每次生图/下载成功或失败会自动写入日志:`scripts/output/logs/YYYY-MM-DD.log`,可 `cat``tail` 查看历史记录。
## 所有生图方式 ## 所有生图方式
### 文生图 ### 文生图
+27 -2
View File
@@ -7,6 +7,25 @@ import { config } from './config.js';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
// ── 日志记录 ──
const LOG_DIR = path.join(config.outputDir, 'logs');
function ensureLogDir() {
try { fs.mkdirSync(LOG_DIR, { recursive: true }); } catch {}
}
function todayLogFile() {
const d = new Date();
const pad = (n) => String(n).padStart(2, '0');
return path.join(LOG_DIR, `${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())}.log`);
}
function logToFile(message) {
ensureLogDir();
const ts = new Date().toISOString();
fs.appendFileSync(todayLogFile(), `[${ts}] ${message}\n`);
}
const sleep = (ms) => new Promise(r => setTimeout(r, ms)); const sleep = (ms) => new Promise(r => setTimeout(r, ms));
/** /**
@@ -393,12 +412,14 @@ close 参数:
}); });
const chatUrl = await captureChatUrl(sid, page); const chatUrl = await captureChatUrl(sid, page);
const images = downloaded.map(i => i.path);
logToFile(`DOWNLOAD_ONLY | session=${sid} | chatUrl=${chatUrl} | images=${images.join(',')}`);
emit('success', { emit('success', {
sessionId: sid, sessionId: sid,
chatUrl, chatUrl,
mode, mode,
images: downloaded.map(i => i.path), images,
}); });
} catch (e) { } catch (e) {
emit('error', { emit('error', {
@@ -462,12 +483,15 @@ close 参数:
// Remove internal fields from output // Remove internal fields from output
delete result.existingButtonCount; delete result.existingButtonCount;
const genImages = result.images?.map(i => i.path) || [];
logToFile(`GENERATE | session=${sid} | chatUrl=${chatUrl} | mode=${mode} | images=${genImages.join(',')}`);
// Emit final success event // Emit final success event
emit('success', { emit('success', {
sessionId: sid, sessionId: sid,
chatUrl, chatUrl,
mode, mode,
images: result.images?.map(i => i.path) || [], images: genImages,
}); });
} else if (result.status === 'text_only') { } else if (result.status === 'text_only') {
// Text-only response means image generation failed // Text-only response means image generation failed
@@ -478,6 +502,7 @@ close 参数:
}); });
} else { } else {
// Error or timeout — emit error as terminal event // Error or timeout — emit error as terminal event
logToFile(`GENERATE_ERROR | session=${sid} | status=${result.status} | ${result.message}`);
emit('error', { emit('error', {
message: result.message, message: result.message,
sessionId: sid, sessionId: sid,