feat: 添加按日分割的日志记录(output/logs/YYYY-MM-DD.log)
This commit is contained in:
@@ -25,6 +25,8 @@ CLI 自动完成:打开标签页 → 导航 → 粘贴参考图 → 输入提
|
||||
|
||||
生图完成后将图片移到目标位置,通过 `message` 工具发送。
|
||||
|
||||
每次生图/下载成功或失败会自动写入日志:`scripts/output/logs/YYYY-MM-DD.log`,可 `cat` 或 `tail` 查看历史记录。
|
||||
|
||||
## 所有生图方式
|
||||
|
||||
### 文生图
|
||||
|
||||
@@ -7,6 +7,25 @@ import { config } from './config.js';
|
||||
import fs from 'fs';
|
||||
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));
|
||||
|
||||
/**
|
||||
@@ -393,12 +412,14 @@ close 参数:
|
||||
});
|
||||
|
||||
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', {
|
||||
sessionId: sid,
|
||||
chatUrl,
|
||||
mode,
|
||||
images: downloaded.map(i => i.path),
|
||||
images,
|
||||
});
|
||||
} catch (e) {
|
||||
emit('error', {
|
||||
@@ -462,12 +483,15 @@ close 参数:
|
||||
// Remove internal fields from output
|
||||
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('success', {
|
||||
sessionId: sid,
|
||||
chatUrl,
|
||||
mode,
|
||||
images: result.images?.map(i => i.path) || [],
|
||||
images: genImages,
|
||||
});
|
||||
} else if (result.status === 'text_only') {
|
||||
// Text-only response means image generation failed
|
||||
@@ -478,6 +502,7 @@ close 参数:
|
||||
});
|
||||
} else {
|
||||
// Error or timeout — emit error as terminal event
|
||||
logToFile(`GENERATE_ERROR | session=${sid} | status=${result.status} | ${result.message}`);
|
||||
emit('error', {
|
||||
message: result.message,
|
||||
sessionId: sid,
|
||||
|
||||
Reference in New Issue
Block a user