export class McpLogger {
    loggerName;
    constructor(loggerName = "skyramp-mcp") {
        this.loggerName = loggerName;
    }
    sendLogMessage(level, message, data) {
        // MCP servers should use console.error for logging to stderr per MCP spec
        // This ensures logs are properly captured by MCP clients and don't interfere
        // with the JSON-RPC protocol communication on stdout
        // Check if stderr is still writable before attempting to write
        if (!process.stderr || !process.stderr.writable) {
            return;
        }
        const timestamp = new Date().toISOString();
        const logEntry = {
            timestamp,
            level: level.toUpperCase(),
            logger: this.loggerName,
            message,
            ...(data && { data }),
        };
        try {
            console.error(JSON.stringify(logEntry));
        }
        catch (error) {
            // silently ignore
        }
    }
    debug(message, data) {
        this.sendLogMessage("debug", message, data);
    }
    info(message, data) {
        this.sendLogMessage("info", message, data);
    }
    warning(message, data) {
        this.sendLogMessage("warning", message, data);
    }
    error(message, data) {
        this.sendLogMessage("error", message, data);
    }
    critical(message, data) {
        this.sendLogMessage("critical", message, data);
    }
}
// Export singleton instance
export const logger = new McpLogger();
