Files
NebulaShell/oss/logger/logger.py
Falck bce27db4ac 重大重构:引擎模块拆分 + P0插件实现 + 55个Bug修复
核心变更:
- engine.py(1781行)拆分为8个独立模块: lifecycle/security/deps/
  datastore/pl_injector/watcher/signature/manager
- 新增plugin-bridge: 事件总线 + 服务注册 + RPC通信
- 新增i18n: 国际化/多语言翻译支持
- 新增plugin-storage: 插件键值/文件存储
- 新增ws-api: WebSocket实时通信(pub/sub + 自定义处理器)
- nodejs-adapter统一为Plugin ABC模式

Bug修复:
- 修复load_all()中store_dir未定义崩溃
- 修复DependencyResolver入度计算(拓扑排序)
- 修复PermissionError隐藏内置异常
- 修复CORS中间件头部未附加到响应
- 修复IntegrityChecker跳过__pycache__目录
- 修复版本号不一致(v2.0.0→v1.2.0)
- 修复测试文件的Logger导入/路径/私有方法调用
- 修复context.py缺少typing导入
- 修复config.py STORE_DIR默认路径(./mods→./store)

测试覆盖: 14→91个测试, 全部通过
2026-05-12 11:40:06 +08:00

82 lines
2.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""日志系统 - 彩色日志"""
import sys
class Log:
"""通用彩色日志 - 所有插件可共用"""
_TTY = sys.stdout.isatty()
_C = {
"reset": "\033[0m",
"white": "\033[0;37m",
"yellow": "\033[1;33m",
"blue": "\033[1;34m",
"red": "\033[1;31m",
"green": "\033[0;32m",
}
@classmethod
def _c(cls, text: str, color: str) -> str:
if not cls._TTY:
return text
return f"{cls._C.get(color, '')}{text}{cls._C['reset']}"
@classmethod
def info(cls, tag: str, msg: str):
print(f"{cls._c(f'[{tag}]', 'white')} {cls._c(msg, 'white')}")
@classmethod
def warn(cls, tag: str, msg: str):
print(f"{cls._c(f'[{tag}]', 'yellow')} {cls._c('', 'yellow')} {cls._c(msg, 'yellow')}")
@classmethod
def error(cls, tag: str, msg: str):
print(f"{cls._c(f'[{tag}]', 'red')} {cls._c('', 'red')} {cls._c(msg, 'red')}")
@classmethod
def tip(cls, tag: str, msg: str):
print(f"{cls._c(f'[{tag}]', 'blue')} {cls._c('', 'blue')} {cls._c(msg, 'blue')}")
@classmethod
def ok(cls, tag: str, msg: str):
print(f"{cls._c(f'[{tag}]', 'white')} {cls._c(msg, 'white')}")
@classmethod
def debug(cls, tag: str, msg: str):
cls.tip(tag, msg)
class Logger:
"""Instance-based logger wrapper for backward compatibility.
Usage: logger = Logger(); logger.info('tag', 'message')
"""
def info(self, tag: str, msg: str = ""):
if not msg:
tag, msg = "Logger", tag
Log.info(tag, msg)
def warn(self, tag: str, msg: str = ""):
if not msg:
tag, msg = "Logger", tag
Log.warn(tag, msg)
def error(self, tag: str, msg: str = ""):
if not msg:
tag, msg = "Logger", tag
Log.error(tag, msg)
def debug(self, tag: str, msg: str = ""):
if not msg:
tag, msg = "Logger", tag
Log.debug(tag, msg)
def tip(self, tag: str, msg: str = ""):
if not msg:
tag, msg = "Logger", tag
Log.tip(tag, msg)
def ok(self, tag: str, msg: str = ""):
if not msg:
tag, msg = "Logger", tag
Log.ok(tag, msg)