@storm-software/config-tools
Version:
⚡The Storm-Ops monorepo contains utility applications, tools, and various libraries to create modern and scalable web applications.
142 lines (113 loc) • 9.42 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var _chunkYSSMM2WQcjs = require('./chunk-YSSMM2WQ.cjs');
var _chunkVICC23NVcjs = require('./chunk-VICC23NV.cjs');
var _chunkKBPYCUVGcjs = require('./chunk-KBPYCUVG.cjs');
var _chunkIGUYFX5Bcjs = require('./chunk-IGUYFX5B.cjs');
var _chunk7HCO3WBNcjs = require('./chunk-7HCO3WBN.cjs');
var _chunkC5OTFOQBcjs = require('./chunk-C5OTFOQB.cjs');
var _chunkUSNT2KNTcjs = require('./chunk-USNT2KNT.cjs');
// src/logger/console.ts
var getLogFn = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (logLevel = _chunkC5OTFOQBcjs.LogLevel.INFO, config = {}, _chalk = _chunkVICC23NVcjs.getChalk.call(void 0, )) => {
const colors = !_optionalChain([config, 'access', _2 => _2.colors, 'optionalAccess', _3 => _3.dark]) && !_optionalChain([config, 'access', _4 => _4.colors, 'optionalAccess', _5 => _5["base"]]) && !_optionalChain([config, 'access', _6 => _6.colors, 'optionalAccess', _7 => _7["base"], 'optionalAccess', _8 => _8.dark]) ? _chunkYSSMM2WQcjs.DEFAULT_COLOR_CONFIG : _optionalChain([config, 'access', _9 => _9.colors, 'optionalAccess', _10 => _10.dark]) && typeof config.colors.dark === "string" ? config.colors : _optionalChain([config, 'access', _11 => _11.colors, 'optionalAccess', _12 => _12["base"], 'optionalAccess', _13 => _13.dark]) && typeof config.colors["base"].dark === "string" ? config.colors["base"].dark : _optionalChain([config, 'access', _14 => _14.colors, 'optionalAccess', _15 => _15["base"]]) ? _optionalChain([config, 'access', _16 => _16.colors, 'optionalAccess', _17 => _17["base"]]) : _chunkYSSMM2WQcjs.DEFAULT_COLOR_CONFIG;
const configLogLevel = config.logLevel || process.env.STORM_LOG_LEVEL || _chunkC5OTFOQBcjs.LogLevelLabel.INFO;
if (logLevel > _chunk7HCO3WBNcjs.getLogLevel.call(void 0, configLogLevel) || logLevel <= _chunkC5OTFOQBcjs.LogLevel.SILENT || _chunk7HCO3WBNcjs.getLogLevel.call(void 0, configLogLevel) <= _chunkC5OTFOQBcjs.LogLevel.SILENT) {
return (_) => {
};
}
if (typeof logLevel === "number" && _chunkC5OTFOQBcjs.LogLevel.FATAL >= logLevel) {
return (message) => {
console.error(`
${_chalk.gray(_chunkIGUYFX5Bcjs.formatTimestamp.call(void 0, ))} ${_chalk.hex(_nullishCoalesce(colors.fatal, () => ( "#7d1a1a")))(`[${_chunkKBPYCUVGcjs.CONSOLE_ICONS[_chunkC5OTFOQBcjs.LogLevelLabel.FATAL]} Fatal] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
`);
};
}
if (typeof logLevel === "number" && _chunkC5OTFOQBcjs.LogLevel.ERROR >= logLevel) {
return (message) => {
console.error(`
${_chalk.gray(_chunkIGUYFX5Bcjs.formatTimestamp.call(void 0, ))} ${_chalk.hex(_nullishCoalesce(colors.danger, () => ( "#f85149")))(`[${_chunkKBPYCUVGcjs.CONSOLE_ICONS[_chunkC5OTFOQBcjs.LogLevelLabel.ERROR]} Error] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
`);
};
}
if (typeof logLevel === "number" && _chunkC5OTFOQBcjs.LogLevel.WARN >= logLevel) {
return (message) => {
console.warn(`
${_chalk.gray(_chunkIGUYFX5Bcjs.formatTimestamp.call(void 0, ))} ${_chalk.hex(_nullishCoalesce(colors.warning, () => ( "#e3b341")))(`[${_chunkKBPYCUVGcjs.CONSOLE_ICONS[_chunkC5OTFOQBcjs.LogLevelLabel.WARN]} Warn] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
`);
};
}
if (typeof logLevel === "number" && _chunkC5OTFOQBcjs.LogLevel.SUCCESS >= logLevel) {
return (message) => {
console.info(`
${_chalk.gray(_chunkIGUYFX5Bcjs.formatTimestamp.call(void 0, ))} ${_chalk.hex(_nullishCoalesce(colors.success, () => ( "#56d364")))(`[${_chunkKBPYCUVGcjs.CONSOLE_ICONS[_chunkC5OTFOQBcjs.LogLevelLabel.SUCCESS]} Success] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
`);
};
}
if (typeof logLevel === "number" && _chunkC5OTFOQBcjs.LogLevel.INFO >= logLevel) {
return (message) => {
console.info(`
${_chalk.gray(_chunkIGUYFX5Bcjs.formatTimestamp.call(void 0, ))} ${_chalk.hex(_nullishCoalesce(colors.info, () => ( "#58a6ff")))(`[${_chunkKBPYCUVGcjs.CONSOLE_ICONS[_chunkC5OTFOQBcjs.LogLevelLabel.INFO]} Info] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
`);
};
}
if (typeof logLevel === "number" && _chunkC5OTFOQBcjs.LogLevel.DEBUG >= logLevel) {
return (message) => {
console.debug(`
${_chalk.gray(_chunkIGUYFX5Bcjs.formatTimestamp.call(void 0, ))} ${_chalk.hex(_nullishCoalesce(colors.brand, () => ( "#1fb2a6")))(`[${_chunkKBPYCUVGcjs.CONSOLE_ICONS[_chunkC5OTFOQBcjs.LogLevelLabel.DEBUG]} Debug] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
`);
};
}
if (typeof logLevel === "number" && _chunkC5OTFOQBcjs.LogLevel.TRACE >= logLevel) {
return (message) => {
console.debug(`
${_chalk.gray(_chunkIGUYFX5Bcjs.formatTimestamp.call(void 0, ))} ${_chalk.hex(_nullishCoalesce(colors.brand, () => ( "#1fb2a6")))(`[${_chunkKBPYCUVGcjs.CONSOLE_ICONS[_chunkC5OTFOQBcjs.LogLevelLabel.TRACE]} Trace] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
`);
};
}
return (message) => {
console.log(`
${_chalk.gray(_chunkIGUYFX5Bcjs.formatTimestamp.call(void 0, ))} ${_chalk.hex(_nullishCoalesce(colors.brand, () => ( "#1fb2a6")))(`[${_chunkKBPYCUVGcjs.CONSOLE_ICONS[_chunkC5OTFOQBcjs.LogLevelLabel.ALL]} System] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
`);
};
}, "getLogFn");
var writeFatal = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (message, config) => getLogFn(_chunkC5OTFOQBcjs.LogLevel.FATAL, config)(message), "writeFatal");
var writeError = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (message, config) => getLogFn(_chunkC5OTFOQBcjs.LogLevel.ERROR, config)(message), "writeError");
var writeWarning = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (message, config) => getLogFn(_chunkC5OTFOQBcjs.LogLevel.WARN, config)(message), "writeWarning");
var writeInfo = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (message, config) => getLogFn(_chunkC5OTFOQBcjs.LogLevel.INFO, config)(message), "writeInfo");
var writeSuccess = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (message, config) => getLogFn(_chunkC5OTFOQBcjs.LogLevel.SUCCESS, config)(message), "writeSuccess");
var writeDebug = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (message, config) => getLogFn(_chunkC5OTFOQBcjs.LogLevel.DEBUG, config)(message), "writeDebug");
var writeTrace = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (message, config) => getLogFn(_chunkC5OTFOQBcjs.LogLevel.TRACE, config)(message), "writeTrace");
var writeSystem = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (message, config) => getLogFn(_chunkC5OTFOQBcjs.LogLevel.ALL, config)(message), "writeSystem");
var getStopwatch = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (name) => {
const start = process.hrtime();
return () => {
const end = process.hrtime(start);
console.info(`
> \u23F1\uFE0F The${name ? ` ${name}` : ""} process took ${Math.round(end[0] * 1e3 + end[1] / 1e6)}ms to complete
`);
};
}, "getStopwatch");
var MAX_DEPTH = 4;
var formatLogMessage = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (message, options = {}, depth = 0) => {
if (depth > MAX_DEPTH) {
return "<max depth>";
}
const prefix = _nullishCoalesce(options.prefix, () => ( "-"));
const skip = _nullishCoalesce(options.skip, () => ( []));
return typeof message === "undefined" || message === null || !message && typeof message !== "boolean" ? "<none>" : typeof message === "string" ? message : Array.isArray(message) ? `
${message.map((item, index) => ` ${prefix}> #${index} = ${formatLogMessage(item, {
prefix: `${prefix}-`,
skip
}, depth + 1)}`).join("\n")}` : typeof message === "object" ? `
${Object.keys(message).filter((key) => !skip.includes(key)).map((key) => ` ${prefix}> ${key} = ${_isFunction(message[key]) ? "<function>" : typeof message[key] === "object" ? formatLogMessage(message[key], {
prefix: `${prefix}-`,
skip
}, depth + 1) : message[key]}`).join("\n")}` : message;
}, "formatLogMessage");
var _isFunction = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (value) => {
try {
return value instanceof Function || typeof value === "function" || !!(_optionalChain([value, 'optionalAccess', _18 => _18.constructor]) && _optionalChain([value, 'optionalAccess', _19 => _19.call]) && _optionalChain([value, 'optionalAccess', _20 => _20.apply]));
} catch (e) {
return false;
}
}, "_isFunction");
exports.getLogFn = getLogFn; exports.writeFatal = writeFatal; exports.writeError = writeError; exports.writeWarning = writeWarning; exports.writeInfo = writeInfo; exports.writeSuccess = writeSuccess; exports.writeDebug = writeDebug; exports.writeTrace = writeTrace; exports.writeSystem = writeSystem; exports.getStopwatch = getStopwatch; exports.formatLogMessage = formatLogMessage;