mcp-ai-agent-guidelines
Version:
A comprehensive Model Context Protocol server providing advanced tools, resources, and prompts for implementing AI agent best practices
53 lines • 1.45 kB
JavaScript
/**
* Structured logging utility for production code
* Provides consistent, queryable log output for monitoring and debugging
*/
/**
* Structured logger that outputs JSON-formatted log messages
* for improved monitoring and debuggability in production
*/
class Logger {
/**
* Log a warning message with optional context
*/
warn(message, context) {
this.log("warn", message, context);
}
/**
* Log an error message with optional context
*/
error(message, context) {
this.log("error", message, context);
}
/**
* Log an info message with optional context
*/
info(message, context) {
this.log("info", message, context);
}
/**
* Log a debug message with optional context
*/
debug(message, context) {
this.log("debug", message, context);
}
/**
* Internal logging method that outputs structured JSON
*/
log(level, message, context) {
const logEntry = {
timestamp: new Date().toISOString(),
level,
message,
...(context && { context }),
};
// Output to stderr for warn/error, stdout for info/debug
const output = level === "warn" || level === "error" ? console.error : console.log;
output(JSON.stringify(logEntry));
}
}
/**
* Singleton logger instance
*/
export const logger = new Logger();
//# sourceMappingURL=logger.js.map