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