Skip to main content
Glama
logger.md2.42 kB
```typescript import winston from "winston"; // ============================================ // Formatting // ============================================ const logFormat = winston.format.combine( winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston.format.errors({ stack: true }), winston.format.splat(), winston.format.json(), ); const consoleFormat = winston.format.combine( winston.format.colorize(), winston.format.printf(({ level, message, timestamp, stack, ...meta }) => { let msg = `${timestamp} [${level}]: ${message}`; if (stack) { msg += `\n${stack}`; } if (Object.keys(meta).length > 0) { msg += `\n${JSON.stringify(meta, null, 2)}`; } return msg; }), ); // ============================================ // Logger Instance // ============================================ export const logger = winston.createLogger({ level: process.env.LOG_LEVEL || "info", format: logFormat, defaultMeta: { service: "my-app" }, transports: [ // Console transport new winston.transports.Console({ format: consoleFormat, }), // File transports (production only usually) new winston.transports.File({ filename: "logs/error.log", level: "error", maxsize: 5242880, // 5MB maxFiles: 5, }), new winston.transports.File({ filename: "logs/combined.log", maxsize: 5242880, // 5MB maxFiles: 5, }), ], }); // ============================================ // Request Logger Middleware // ============================================ /* import { Request, Response, NextFunction } from 'express'; export const requestLogger = (req: Request, res: Response, next: NextFunction) => { const start = Date.now(); res.on('finish', () => { const duration = Date.now() - start; logger.info('HTTP Request', { method: req.method, url: req.originalUrl, status: res.statusCode, duration: `${duration}ms`, ip: req.ip, userAgent: req.get('user-agent'), }); }); next(); }; */ // ============================================ // Usage // ============================================ /* logger.info('Server started', { port: 3000 }); logger.warn('Rate limit exceeded', { ip: '192.168.1.1' }); logger.error('Database connection failed', new Error('Connection timeout')); */ ```

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/millsydotdev/Code-MCP'

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