UNPKG

972 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.isLogLevelEnabled = void 0;
4const LOG_LEVEL_VALUES = {
5 debug: 0,
6 verbose: 1,
7 log: 2,
8 warn: 3,
9 error: 4,
10};
11/**
12 * Checks if target level is enabled.
13 * @param targetLevel target level
14 * @param logLevels array of enabled log levels
15 */
16function isLogLevelEnabled(targetLevel, logLevels) {
17 var _a;
18 if (!logLevels || (Array.isArray(logLevels) && (logLevels === null || logLevels === void 0 ? void 0 : logLevels.length) === 0)) {
19 return false;
20 }
21 if (logLevels.includes(targetLevel)) {
22 return true;
23 }
24 const highestLogLevelValue = (_a = logLevels
25 .map(level => LOG_LEVEL_VALUES[level])
26 .sort((a, b) => b - a)) === null || _a === void 0 ? void 0 : _a[0];
27 const targetLevelValue = LOG_LEVEL_VALUES[targetLevel];
28 return targetLevelValue >= highestLogLevelValue;
29}
30exports.isLogLevelEnabled = isLogLevelEnabled;