Files
zclaw_openfang/desktop/src/lib/logger.ts
iven 978dc5cdd8
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
fix(安全): 修复HTML导出中的XSS漏洞并清理调试日志
refactor(日志): 替换console.log为tracing日志系统
style(代码): 移除未使用的代码和依赖项

feat(测试): 添加端到端测试文档和CI工作流
docs(变更日志): 更新CHANGELOG.md记录0.1.0版本变更

perf(构建): 更新依赖版本并优化CI流程
2026-03-26 19:49:03 +08:00

48 lines
1.3 KiB
TypeScript

/**
* ZCLAW Logger
*
* Unified logging utility. In production builds, debug and trace logs are suppressed.
* Warn and error logs are always emitted.
*/
const isDev = import.meta.env.DEV;
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
function shouldLog(level: LogLevel): boolean {
if (level === 'warn' || level === 'error') return true;
return isDev;
}
export const logger = {
debug(message: string, ...args: unknown[]): void {
if (shouldLog('debug')) {
console.debug(message, ...args);
}
},
info(message: string, ...args: unknown[]): void {
if (shouldLog('info')) {
console.info(message, ...args);
}
},
warn(message: string, ...args: unknown[]): void {
console.warn(message, ...args);
},
error(message: string, ...args: unknown[]): void {
console.error(message, ...args);
},
};
export function createLogger(target: string) {
const prefix = `[${target}]`;
return {
debug: (message: string, ...args: unknown[]) => logger.debug(`${prefix} ${message}`, ...args),
info: (message: string, ...args: unknown[]) => logger.info(`${prefix} ${message}`, ...args),
warn: (message: string, ...args: unknown[]) => logger.warn(`${prefix} ${message}`, ...args),
error: (message: string, ...args: unknown[]) => logger.error(`${prefix} ${message}`, ...args),
};
}