feat: enhance logging capabilities, implement runtime diagnostics, and update preinstalled skills metadata

This commit is contained in:
DEV_DSW
2026-04-27 17:00:51 +08:00
parent 90e02636c7
commit 2081f583e3
9 changed files with 354 additions and 24 deletions

View File

@@ -1,10 +1,11 @@
import { IPC_EVENTS } from '@runtime/lib/constants';
import { promisify } from 'util';
import { ipcMain } from 'electron';
import { app, ipcMain } from 'electron';
import log from 'electron-log';
import * as path from 'path';
import * as fs from 'fs';
import { getUserDataDir } from '@electron/utils/paths';
import { serializeUnknownError } from '@electron/utils/log-helpers';
// 转换为Promise形式的fs方法
const readdirAsync = promisify(fs.readdir);
@@ -35,6 +36,12 @@ class LogService {
this.error('Failed to create log directory:', err);
}
try {
app.setAppLogsPath(logPath);
} catch (err) {
this.error('Failed to set app logs path:', err);
}
// 配置electron-log
log.transports.file.resolvePathFn = () => {
// 使用当前日期作为日志文件名,格式为 YYYY-MM-DD.log
@@ -48,6 +55,7 @@ class LogService {
// 配置日志文件大小限制默认10MB
log.transports.file.maxSize = 10 * 1024 * 1024; // 10MB
log.transports.file.sync = true;
// 配置控制台日志级别开发环境可以设置为debug生产环境可以设置为info
log.transports.console.level = process.env.NODE_ENV === 'development' ? 'debug' : 'info';
@@ -160,6 +168,13 @@ class LogService {
log.error(message, ...meta);
}
public captureException(message: string, error: unknown, extra: Record<string, unknown> = {}): void {
this.error(message, {
...extra,
error: serializeUnknownError(error),
});
}
public logApiRequest(endpoint: string, data: any = {}, method: string = 'POST'): void {
this.info(`API Request: ${endpoint}, Method: ${method}, Request: ${JSON.stringify(data)}`);
@@ -219,6 +234,14 @@ class LogService {
}
}
public getLogDirectoryPath(): string {
return this.logDirPath;
}
public getCurrentLogFilePath(): string {
return this._getCurrentLogFilePath();
}
private _getCurrentLogFilePath(): string {
const today = new Date();
const formattedDate = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}`;