Class: VectorMCP::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/vector_mcp/logger.rb

Overview

Simple, environment-driven logger for VectorMCP Supports JSON and text formats with component-based identification

Constant Summary collapse

LEVELS =
{
  "TRACE" => ::Logger::DEBUG,
  "DEBUG" => ::Logger::DEBUG,
  "INFO" => ::Logger::INFO,
  "WARN" => ::Logger::WARN,
  "ERROR" => ::Logger::ERROR,
  "FATAL" => ::Logger::FATAL
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component = "vectormcp") ⇒ Logger

Returns a new instance of Logger.



21
22
23
24
25
# File 'lib/vector_mcp/logger.rb', line 21

def initialize(component = "vectormcp")
  @component = component.to_s
  @ruby_logger = create_ruby_logger
  @format = ENV.fetch("VECTORMCP_LOG_FORMAT", "text").downcase
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



19
20
21
# File 'lib/vector_mcp/logger.rb', line 19

def component
  @component
end

#ruby_loggerObject (readonly)

Returns the value of attribute ruby_logger.



19
20
21
# File 'lib/vector_mcp/logger.rb', line 19

def ruby_logger
  @ruby_logger
end

Class Method Details

.for(component) ⇒ Object



27
28
29
# File 'lib/vector_mcp/logger.rb', line 27

def self.for(component)
  new(component)
end

Instance Method Details

#debug(message = nil, **context, &block) ⇒ Object

Log methods with context support and block evaluation



32
33
34
# File 'lib/vector_mcp/logger.rb', line 32

def debug(message = nil, **context, &block)
  log(:debug, message || block&.call, context)
end

#error(message = nil, **context, &block) ⇒ Object



44
45
46
# File 'lib/vector_mcp/logger.rb', line 44

def error(message = nil, **context, &block)
  log(:error, message || block&.call, context)
end

#fatal(message = nil, **context, &block) ⇒ Object



48
49
50
# File 'lib/vector_mcp/logger.rb', line 48

def fatal(message = nil, **context, &block)
  log(:fatal, message || block&.call, context)
end

#info(message = nil, **context, &block) ⇒ Object



36
37
38
# File 'lib/vector_mcp/logger.rb', line 36

def info(message = nil, **context, &block)
  log(:info, message || block&.call, context)
end

#measure(description, **context) ⇒ Object

Performance measurement



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/vector_mcp/logger.rb', line 58

def measure(description, **context)
  start_time = Time.now
  result = yield
  duration = Time.now - start_time

  info("#{description} completed", **context, duration_ms: (duration * 1000).round(2),
                                              success: true)

  result
rescue StandardError => e
  duration = Time.now - start_time
  error("#{description} failed", **context, duration_ms: (duration * 1000).round(2),
                                            success: false,
                                            error: e.class.name,
                                            error_message: e.message)
  raise
end

#security(message, **context) ⇒ Object

Security-specific logging



53
54
55
# File 'lib/vector_mcp/logger.rb', line 53

def security(message, **context)
  log(:error, "[SECURITY] #{message}", context.merge(security_event: true))
end

#warn(message = nil, **context, &block) ⇒ Object



40
41
42
# File 'lib/vector_mcp/logger.rb', line 40

def warn(message = nil, **context, &block)
  log(:warn, message || block&.call, context)
end