demoLog.js 609 Bytes
import FloatLogBus from '@/utils/logger/FloatLogBus.js'

const DEMO_TAG = '[AudioDemo]'

export function demoLog(level, msg) {
  const text = `${DEMO_TAG} ${msg}`
  const logger = uni.$logger?.local
  // 只走 logger;若已 install FloatLogBus,logger 监听器会同步到悬浮窗,避免重复打两条
  if (logger?.[level]) {
    logger[level](text)
  } else {
    console.log(text)
    try {
      if (!FloatLogBus.isInstalled()) {
        FloatLogBus.install()
      }
      FloatLogBus.push(level, text)
    } catch (_) {
      /* ignore */
    }
  }
  return { level, text, time: Date.now() }
}