Skip to main content
Glama
logger.ts1.45 kB
import { appendFileSync, existsSync, mkdirSync } from 'fs'; import { join } from 'path'; // Logger that writes to file instead of console (console.log breaks MCP protocol) class FileLogger { private logFile: string; constructor() { // Use environment variable for log directory, fallback to ./logs const logDir = process.env.LOG_DIRECTORY || join(process.cwd(), 'logs'); if (!existsSync(logDir)) { mkdirSync(logDir, { recursive: true }); } this.logFile = join(logDir, `memory-engineering-${new Date().toISOString().split('T')[0]}.log`); } private log(level: string, message: string, ...args: unknown[]): void { const timestamp = new Date().toISOString(); const logEntry = `[${timestamp}] [${level}] ${message} ${ args.length > 0 ? JSON.stringify(args) : '' }\n`; try { appendFileSync(this.logFile, logEntry); } catch (error) { // Silently fail if we can't write logs } } info(message: string, ...args: unknown[]): void { this.log('INFO', message, ...args); } error(message: string, ...args: unknown[]): void { this.log('ERROR', message, ...args); } warn(message: string, ...args: unknown[]): void { this.log('WARN', message, ...args); } debug(message: string, ...args: unknown[]): void { if (process.env.NODE_ENV === 'development') { this.log('DEBUG', message, ...args); } } } export const logger = new FileLogger();

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/romiluz13/memory-engineering-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server