/
githubmirror
/
marktext
Обзор
Документация
Войти
/
githubmirror
/
marktext
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/muya/src/utils/logger.ts
32 строки
848 B
Ran Luo
feat(muya): migrate TS rewrite to packages/muya alongside legacy muyajs (#4314)
29 май 2026, 15:35
Не верифицирован
29 май 2026, 15:35
0d86641
Код
Авторство
О чём код?
type TLevel = 'error' | 'warn' | 'log' | 'info'; const levels: TLevel[] = ['error', 'warn', 'log', 'info']; let level: TLevel = 'log'; type Ilogger = Record<TLevel, (...args: string[]) => void>; function debug(method: TLevel, ...args: unknown[]) { if ( levels.indexOf(method) <= levels.indexOf(level) // eslint-disable-next-line node/prefer-global/process && process.env.NODE_ENV !== 'production' ) { // eslint-disable-next-line no-console console[method](...args); } } function namespace(ns: string): Ilogger { return levels.reduce((logger, method) => { logger[method] = debug.bind(console, method, ns); return logger; }, {} as Ilogger); } namespace.level = (newLevel: TLevel) => { level = newLevel; }; debug.level = namespace.level; export default namespace;