Class: VectorMCP::Logger
- Inherits:
-
Object
- Object
- VectorMCP::Logger
- 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
-
#component ⇒ Object
readonly
Returns the value of attribute component.
-
#ruby_logger ⇒ Object
readonly
Returns the value of attribute ruby_logger.
Class Method Summary collapse
Instance Method Summary collapse
-
#debug(message = nil, **context, &block) ⇒ Object
Log methods with context support and block evaluation.
- #error(message = nil, **context, &block) ⇒ Object
- #fatal(message = nil, **context, &block) ⇒ Object
- #info(message = nil, **context, &block) ⇒ Object
-
#initialize(component = "vectormcp") ⇒ Logger
constructor
A new instance of Logger.
-
#measure(description, **context) ⇒ Object
Performance measurement.
-
#security(message, **context) ⇒ Object
Security-specific logging.
- #warn(message = nil, **context, &block) ⇒ Object
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
#component ⇒ Object (readonly)
Returns the value of attribute component.
19 20 21 |
# File 'lib/vector_mcp/logger.rb', line 19 def component @component end |
#ruby_logger ⇒ Object (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( = nil, **context, &block) log(:debug, || block&.call, context) end |
#error(message = nil, **context, &block) ⇒ Object
44 45 46 |
# File 'lib/vector_mcp/logger.rb', line 44 def error( = nil, **context, &block) log(:error, || block&.call, context) end |
#fatal(message = nil, **context, &block) ⇒ Object
48 49 50 |
# File 'lib/vector_mcp/logger.rb', line 48 def fatal( = nil, **context, &block) log(:fatal, || block&.call, context) end |
#info(message = nil, **context, &block) ⇒ Object
36 37 38 |
# File 'lib/vector_mcp/logger.rb', line 36 def info( = nil, **context, &block) log(:info, || 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.) raise end |
#security(message, **context) ⇒ Object
Security-specific logging
53 54 55 |
# File 'lib/vector_mcp/logger.rb', line 53 def security(, **context) log(:error, "[SECURITY] #{}", 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( = nil, **context, &block) log(:warn, || block&.call, context) end |