fix logviewer
This commit is contained in:
@@ -115,7 +115,7 @@ async function run(options: RunOptions = {}) {
|
||||
path: HOME_DIR,
|
||||
maxFiles: 3,
|
||||
interval: "1d",
|
||||
compress: 'gzip',
|
||||
compress: false,
|
||||
maxSize: "50M"
|
||||
}),
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ export const createServer = (config: any): Server => {
|
||||
}
|
||||
|
||||
const logContent = readFileSync(logFilePath, 'utf8');
|
||||
const logLines = logContent.split('\n').filter(line => line.trim());
|
||||
const logLines = logContent.split('\n').filter(line => line.trim())
|
||||
|
||||
return logLines;
|
||||
} catch (error) {
|
||||
|
||||
@@ -11,11 +11,15 @@ import {join} from "path";
|
||||
export async function executeCodeCommand(args: string[] = []) {
|
||||
// Set environment variables
|
||||
const config = await readConfigFile();
|
||||
const port = config.PORT || 3456;
|
||||
const env: Record<string, string> = {
|
||||
...process.env,
|
||||
ANTHROPIC_AUTH_TOKEN: config?.APIKEY || "test",
|
||||
ANTHROPIC_API_KEY: '',
|
||||
ANTHROPIC_BASE_URL: `http://127.0.0.1:${config.PORT || 3456}`,
|
||||
ANTHROPIC_BASE_URL: `http://127.0.0.1:${port}`,
|
||||
NO_PROXY: `127.0.0.1`,
|
||||
DISABLE_TELEMETRY: 'true',
|
||||
DISABLE_COST_WARNINGS: 'true',
|
||||
API_TIMEOUT_MS: String(config.API_TIMEOUT_MS ?? 600000), // Default to 10 minutes if not set
|
||||
};
|
||||
let settingsFlag: Record<string, any> | undefined;
|
||||
|
||||
@@ -85,19 +85,8 @@ export function LogViewer({ open, onOpenChange, showToast }: LogViewerProps) {
|
||||
const groupedLogs = {};
|
||||
|
||||
logs.forEach((log, index) => {
|
||||
let reqId = log.reqId;
|
||||
|
||||
// 如果没有reqId,尝试从message字段中的JSON解析
|
||||
if (!reqId && log.message && log.message.startsWith('{')) {
|
||||
try {
|
||||
const messageObj = JSON.parse(log.message);
|
||||
reqId = messageObj.reqId;
|
||||
} catch (e) {
|
||||
// 解析失败,忽略
|
||||
}
|
||||
}
|
||||
|
||||
reqId = reqId || 'no-req-id';
|
||||
log = JSON.parse(log);
|
||||
let reqId = log.reqId || 'no-req-id';
|
||||
|
||||
if (!groupedLogs[reqId]) {
|
||||
groupedLogs[reqId] = [];
|
||||
@@ -107,7 +96,7 @@ export function LogViewer({ open, onOpenChange, showToast }: LogViewerProps) {
|
||||
|
||||
// 按时间戳排序每个组的日志
|
||||
Object.keys(groupedLogs).forEach(reqId => {
|
||||
groupedLogs[reqId].sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
|
||||
groupedLogs[reqId].sort((a, b) => a.time - b.time);
|
||||
});
|
||||
|
||||
// 提取model信息
|
||||
@@ -116,11 +105,8 @@ export function LogViewer({ open, onOpenChange, showToast }: LogViewerProps) {
|
||||
for (const log of logGroup) {
|
||||
try {
|
||||
// 尝试从message字段解析JSON
|
||||
if (log.message && log.message.startsWith('{')) {
|
||||
const messageObj = JSON.parse(log.message);
|
||||
if (messageObj.body && messageObj.body.model) {
|
||||
return messageObj.body.model;
|
||||
}
|
||||
if (log.type === 'request body' && log.data && log.data.model) {
|
||||
return log.data.model;
|
||||
}
|
||||
} catch (e) {
|
||||
// 解析失败,继续尝试下一条日志
|
||||
@@ -136,8 +122,8 @@ export function LogViewer({ open, onOpenChange, showToast }: LogViewerProps) {
|
||||
requests: Object.keys(groupedLogs).map(reqId => ({
|
||||
reqId,
|
||||
logCount: groupedLogs[reqId].length,
|
||||
firstLog: groupedLogs[reqId][0]?.timestamp,
|
||||
lastLog: groupedLogs[reqId][groupedLogs[reqId].length - 1]?.timestamp,
|
||||
firstLog: groupedLogs[reqId][0]?.time,
|
||||
lastLog: groupedLogs[reqId][groupedLogs[reqId].length - 1]?.time,
|
||||
model: extractModelInfo(reqId)
|
||||
}))
|
||||
};
|
||||
@@ -298,17 +284,17 @@ export function LogViewer({ open, onOpenChange, showToast }: LogViewerProps) {
|
||||
|
||||
// 如果启用了分组,使用Web Worker进行聚合(需要转换为LogEntry格式供Worker使用)
|
||||
if (groupByReqId && workerRef.current) {
|
||||
const workerLogs: LogEntry[] = response.map((logLine, index) => ({
|
||||
timestamp: new Date().toISOString(),
|
||||
level: 'info',
|
||||
message: logLine,
|
||||
source: undefined,
|
||||
reqId: undefined
|
||||
}));
|
||||
// const workerLogs: LogEntry[] = response.map((logLine, index) => ({
|
||||
// timestamp: new Date().toISOString(),
|
||||
// level: 'info',
|
||||
// message: logLine,
|
||||
// source: undefined,
|
||||
// reqId: undefined
|
||||
// }));
|
||||
|
||||
workerRef.current.postMessage({
|
||||
type: 'groupLogsByReqId',
|
||||
data: { logs: workerLogs }
|
||||
data: { logs: response }
|
||||
});
|
||||
} else {
|
||||
setGroupedLogs(null);
|
||||
@@ -512,8 +498,9 @@ export function LogViewer({ open, onOpenChange, showToast }: LogViewerProps) {
|
||||
// 如果在分组模式且选中了具体请求,显示该请求的日志
|
||||
if (groupByReqId && groupedLogs && selectedReqId && groupedLogs.groups[selectedReqId]) {
|
||||
const requestLogs = groupedLogs.groups[selectedReqId];
|
||||
console.log(requestLogs)
|
||||
// 提取原始JSON字符串并每行一个
|
||||
return requestLogs.map(log => log.message).join('\n');
|
||||
return requestLogs.map(log => JSON.stringify(log)).join('\n');
|
||||
}
|
||||
|
||||
// 其他情况,直接显示原始日志字符串数组,每行一个
|
||||
|
||||
Reference in New Issue
Block a user