quality-mcp
Version:
An MCP server that analyzes to your codebase, with plugin support for DCD and Simian. 🏍️ "The only Zen you find on the tops of mountains is the Zen you bring up there."
104 lines (86 loc) • 2.35 kB
JavaScript
/**
* Logger utility
* Simple logging system for the Quality MCP server
*/
const LOG_LEVELS = {
debug: 0,
info: 1,
warn: 2,
error: 3,
};
const LOG_COLORS = {
debug: '\x1b[36m', // cyan
info: '\x1b[32m', // green
warn: '\x1b[33m', // yellow
error: '\x1b[31m', // red
reset: '\x1b[0m', // reset
};
class Logger {
constructor(module = 'app') {
this.module = module;
this.level = process.env.LOG_LEVEL || 'info';
this.useColors = process.env.NO_COLOR !== '1' && process.stdout.isTTY;
}
formatMessage(level, message, ...args) {
const timestamp = new Date().toISOString();
const moduleStr = `[${this.module}]`;
const levelStr = level.toUpperCase().padEnd(5);
let formattedMessage = `${timestamp} ${levelStr} ${moduleStr} ${message}`;
if (args.length > 0) {
const argsStr = args
.map(arg => {
return typeof arg === 'object' ? JSON.stringify(arg, null, 2) : String(arg);
})
.join(' ');
formattedMessage += ` ${argsStr}`;
}
if (this.useColors && LOG_COLORS[level]) {
return `${LOG_COLORS[level]}${formattedMessage}${LOG_COLORS.reset}`;
}
return formattedMessage;
}
shouldLog(level) {
return LOG_LEVELS[level] >= LOG_LEVELS[this.level];
}
debug(message, ...args) {
if (this.shouldLog('debug')) {
console.log(this.formatMessage('debug', message, ...args));
}
}
info(message, ...args) {
if (this.shouldLog('info')) {
console.log(this.formatMessage('info', message, ...args));
}
}
warn(message, ...args) {
if (this.shouldLog('warn')) {
console.warn(this.formatMessage('warn', message, ...args));
}
}
error(message, ...args) {
if (this.shouldLog('error')) {
console.error(this.formatMessage('error', message, ...args));
}
}
setLevel(level) {
if (LOG_LEVELS[level] !== undefined) {
this.level = level;
}
}
}
/**
* Create a logger instance for a specific module
* @param {string} module - Module name for logging context
* @returns {Logger} Logger instance
*/
export function createLogger(module) {
return new Logger(module);
}
/**
* Set the global log level
* @param {string} level - Log level (debug, info, warn, error)
*/
export function setLogLevel(level) {
process.env.LOG_LEVEL = level;
}
export { Logger };