@eljs/utils
Version:
Collection of nodejs utility.
37 lines (34 loc) • 1.08 kB
JavaScript
import debug from 'debug';
var DEBUG = process.env.DEBUG;
/**
* 调试配置项
*/
/**
* 创建调试器
* @param namespace 命名空间
* @param options 可选配置项
*/
export function createDebugger(namespace) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var log = debug(namespace);
var onlyWhenFocused = options.onlyWhenFocused,
depth = options.depth;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (depth && log.inspectOpts && log.inspectOpts.depth == null) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
log.inspectOpts.depth = options.depth;
}
var enabled = log.enabled;
if (enabled && onlyWhenFocused) {
var ns = typeof onlyWhenFocused === 'string' ? onlyWhenFocused : namespace;
enabled = !!(DEBUG !== null && DEBUG !== void 0 && DEBUG.includes(ns));
}
if (enabled) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return function () {
log.apply(void 0, arguments);
};
}
}