@sigiljs/sigil
Version:
TypeScript-first Node.js HTTP framework offering schema-driven routing, modifier-based middleware, plugin extensibility, and flexible response templating
37 lines (36 loc) • 1.17 kB
JavaScript
let u;
try {
u = require("colors");
} catch {
}
const w = (n, e) => u?.[n] ? u[n](e) : e, s = {};
function j(n, {
message: e,
level: _,
condition: f,
...c
}) {
u?.enable();
const g = typeof e == "function" ? e(w.bind({}, "dim")) : e, m = Array.isArray(g) ? g.join(" ") : g, t = s.isFancy ?? (n?.fancyOutput === void 0 ? process.env?.NODE_ENV !== "production" : n?.fancyOutput);
s.isFancy ??= t;
const d = t ? c.module[0].toUpperCase() + c.module.slice(1) : c.module;
let o = n?.moduleLogger ? n.moduleLogger(d) : n?.logger;
!o && o !== null && (o = console);
const a = {
module: d,
level: _,
timestamp: Date.now(),
data: c.json ?? { message: m }
}, r = t ? m : JSON.stringify(a), l = s.infoLog ?? (o?.debug || o?.log || o?.info), L = s.warningLog ?? (o?.warn || o?.warning), p = s.successLog ?? (o?.success || l);
s.infoLog ??= l, s._warnLog ??= L, s._successLog ??= p;
const y = o?.[_] || l || L;
let i;
typeof f < "u" ? f && (i = t ? y?.(r) : l?.(r)) : i = t ? y?.(r) : l?.(r), c.json && i && "json" in i && (i.json = {
__module: a.module,
__level: a.level,
...a.data
});
}
export {
j as default
};