mirror of
https://github.com/Wx-2025/ST-Amily2-Chat-Optimisation.git
synced 2026-06-10 01:55:51 +00:00
增强日志记录功能,添加安全控制台以避免劫持,并在日志处理时输出调试信息
This commit is contained in:
@@ -1,8 +1,26 @@
|
|||||||
import Logger from './log/Logger.js';
|
import Logger from './log/Logger.js';
|
||||||
import FilePipe from './file/FilePipe.js';
|
import FilePipe from './file/FilePipe.js';
|
||||||
|
|
||||||
|
// 【逃生通道】创建一个纯净的 Console 对象,绕过任何潜在的劫持
|
||||||
|
const getSafeConsole = () => {
|
||||||
|
try {
|
||||||
|
if (window._amilySafeConsole) return window._amilySafeConsole;
|
||||||
|
|
||||||
|
const iframe = document.createElement('iframe');
|
||||||
|
iframe.style.display = 'none';
|
||||||
|
document.body.appendChild(iframe);
|
||||||
|
const safe = iframe.contentWindow.console;
|
||||||
|
// document.body.removeChild(iframe); // 保持 iframe 以维持 console 引用有效
|
||||||
|
window._amilySafeConsole = safe;
|
||||||
|
return safe;
|
||||||
|
} catch (e) {
|
||||||
|
return window.console; // Fallback
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class Amily2Bus {
|
class Amily2Bus {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
this.safeConsole = getSafeConsole();
|
||||||
/** @type {Logger|null} */
|
/** @type {Logger|null} */
|
||||||
this.Logger = new Logger();
|
this.Logger = new Logger();
|
||||||
/** @type {FilePipe|null} */
|
/** @type {FilePipe|null} */
|
||||||
@@ -11,7 +29,7 @@ class Amily2Bus {
|
|||||||
// 已注册插件列表,防止重复注册
|
// 已注册插件列表,防止重复注册
|
||||||
this.registry = new Set();
|
this.registry = new Set();
|
||||||
|
|
||||||
console.log('[Amily2Bus] Core container initialized with secure registry.');
|
this.safeConsole.log('[Amily2Bus] Core container initialized with secure registry.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,6 +41,7 @@ class Amily2Bus {
|
|||||||
* @param {string} [plugin='Global'] 来源插件/命名空间,调试时可指定如 'Console'
|
* @param {string} [plugin='Global'] 来源插件/命名空间,调试时可指定如 'Console'
|
||||||
*/
|
*/
|
||||||
log(type, message, origin = 'Bus', plugin = 'Global') {
|
log(type, message, origin = 'Bus', plugin = 'Global') {
|
||||||
|
this.safeConsole.error('[Amily2Bus DEBUG] log called (via SafeConsole):', { type, loggerExists: !!this.Logger });
|
||||||
if (this.Logger) {
|
if (this.Logger) {
|
||||||
this.Logger.process(plugin, origin, type, message);
|
this.Logger.process(plugin, origin, type, message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,6 +144,9 @@ class Logger {
|
|||||||
* 统一处理过滤、格式化和输出,支持默认归属 Global
|
* 统一处理过滤、格式化和输出,支持默认归属 Global
|
||||||
*/
|
*/
|
||||||
process(plugin, origin, type, message, inFile = false) {
|
process(plugin, origin, type, message, inFile = false) {
|
||||||
|
// [DEBUG] 强制输出以确认方法被调用 (使用 error 级别防止被过滤)
|
||||||
|
console.error('[Logger DEBUG] Process called:', { plugin, origin, type, message });
|
||||||
|
|
||||||
// 1. 默认归属处理
|
// 1. 默认归属处理
|
||||||
const safePlugin = plugin || 'Global';
|
const safePlugin = plugin || 'Global';
|
||||||
const safeOrigin = origin || 'System';
|
const safeOrigin = origin || 'System';
|
||||||
|
|||||||
Reference in New Issue
Block a user