/** * 统一日志 */ const PREFIX = '[BLE]' class Logger { constructor() { this.enabled = true } setEnabled(v) { this.enabled = !!v } _fmt(args) { return [PREFIX, ...args] } log(...args) { if (this.enabled) console.log(...this._fmt(args)) } info(...args) { if (this.enabled) console.info(...this._fmt(args)) } warn(...args) { if (this.enabled) console.warn(...this._fmt(args)) } error(...args) { console.error(...this._fmt(args)) } // 错误始终输出 } export default new Logger()