"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
const util_1 = require("util");
function callerInfo() {
var _a, _b, _c;
const lines = (_b = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split('\n')) !== null && _b !== void 0 ? _b : [];
// lines[0] = "Error", lines[1] = current method (fatal/debug), lines[2] = caller
const m = (_c = lines[2]) === null || _c === void 0 ? void 0 : _c.match(/\s+at\s+(?:\w+\s+)?\(?(.+?):(\d+):\d+\)?$/);
return m ? `${m[1]}@${m[2]}` : 'unknown';
}
/** Static logging utility with timestamped levels: fatal, error, warning, info, success, debug. */
class Logger {
static stringify(...message) {
return message.map(m => {
if (m instanceof Object) {
try {
return JSON.stringify(m);
}
catch (_a) {
return (0, util_1.inspect)(m, { colors: true });
}
}
return String(m);
});
}
/** Log an error message and exit the process. */
static fatal(...message) {
console.error(new Date(), '[FATAL]', callerInfo());
console.error(new Date(), '[FATAL]', Logger.stringify(...message).join(' '));
process.exit(1);
}
/** Log an error message. */
static error(...message) {
console.error(new Date(), '[ERROR]', ...message);
}
/** Log a warning message. */
static warning(...message) {
console.warn(new Date(), '[WARNING]', ...message);
}
/** Log an info message. */
static info(...message) {
console.log(new Date(), '[INFO]', ...message);
}
/** Log a success message. */
static success(...message) {
console.log(new Date(), '[SUCCESS]', ...message);
}
/** Log a secondary message (no level tag). */
static secondary(...message) {
console.log(new Date(), ...message);
}
/** Log a primary message (no level tag). */
static primary(...message) {
console.log(new Date(), ...message);
}
/** Log a debug message with file/function/line source information. */
static debug(...message) {
console.log(new Date(), '[DEBUG]', callerInfo());
console.log(new Date(), ' ', Logger.stringify(...message).join(' '));
}
}
exports.Logger = Logger;
//# sourceMappingURL=logger.js.map