@sentzunhat/zacatl
Version:
A modular, high-performance TypeScript microservice framework for Node.js, featuring layered architecture, dependency injection, and robust validation for building scalable APIs and distributed systems.
67 lines • 2.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConsoleLoggerAdapter = void 0;
class ConsoleLoggerAdapter {
enableColors;
enableTimestamps;
constructor(options) {
this.enableColors = options?.colors ?? true;
this.enableTimestamps = options?.timestamps ?? true;
}
formatMessage(level, message, input) {
const timestamp = this.enableTimestamps ? `[${new Date().toISOString()}]` : '';
const levelTag = `[${level.toUpperCase()}]`;
let output = `${timestamp} ${levelTag} ${message}`;
if (input != null) {
const structured = {};
if (input.data !== undefined) {
structured['data'] = input.data;
}
if (input.details !== undefined) {
structured['details'] = input.details;
}
if (Object.keys(structured).length > 0) {
output += ` ${JSON.stringify(structured)}`;
}
}
return output;
}
colorize(text, color) {
if (!this.enableColors)
return text;
const colors = {
reset: '\x1b[0m',
red: '\x1b[31m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
gray: '\x1b[90m',
magenta: '\x1b[35m',
};
return `${colors[color] ?? ''}${text}${colors['reset']}`;
}
log(message, input) {
this.info(message, input);
}
info(message, input) {
const formatted = this.formatMessage('info', message, input);
console.log(this.colorize(formatted, 'blue'));
}
trace(message, input) {
const formatted = this.formatMessage('trace', message, input);
console.log(this.colorize(formatted, 'gray'));
}
warn(message, input) {
const formatted = this.formatMessage('warn', message, input);
console.warn(this.colorize(formatted, 'yellow'));
}
error(message, input) {
const formatted = this.formatMessage('error', message, input);
console.error(this.colorize(formatted, 'red'));
}
fatal(message, input) {
const formatted = this.formatMessage('fatal', message, input);
console.error(this.colorize(formatted, 'magenta'));
}
}
exports.ConsoleLoggerAdapter = ConsoleLoggerAdapter;
//# sourceMappingURL=adapter.js.map