Skip to content

[Improvement] Add Structured Logging #35

@vincentkoc

Description

@vincentkoc

Description

Replace file-based logging with structured logging for better observability.

Current State

  • File-based logging to /tmp/opik-mcp.log
  • Simple text format
  • Limited metadata

Target State

  • Structured JSON logging
  • Multiple log levels
  • Rich metadata
  • Log rotation
  • Multiple outputs

Implementation Options

  1. pino (recommended - fast, low overhead)
  2. winston (feature-rich)

Tasks

  • Choose logging library (pino recommended)
  • Replace all logToFile() calls
  • Configure log levels (error, warn, info, debug, trace)
  • Add structured metadata to logs
  • Configure log rotation
  • Add multiple outputs (file, console, remote)
  • Update configuration for log level control
  • Update documentation

Example with Pino

import pino from 'pino';

const logger = pino({
  level: config.logLevel || 'info',
  transport: {
    target: 'pino-pretty',
    options: { colorize: true }
  }
});

logger.info({ tool: 'get-prompts', duration: 123 }, 'Tool executed');

Log Levels

  • error: Errors that need attention
  • warn: Warnings
  • info: General information
  • debug: Debug information
  • trace: Detailed trace information

Benefits

  • Easier log parsing
  • Better debugging
  • Integration with log aggregators
  • Performance insights

Metadata

Metadata

Assignees

No one assigned

    Labels

    ImprovementIdea on how to make a feature betterenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions