Module: ActionMCP::Logging

Defined in:
lib/action_mcp/logging.rb,
lib/action_mcp/logging/level.rb,
lib/action_mcp/logging/mixin.rb,
lib/action_mcp/logging/state.rb,
lib/action_mcp/logging/logger.rb,
lib/action_mcp/logging/null_logger.rb

Overview

Global MCP logging interface

Defined Under Namespace

Modules: Mixin Classes: Level, Logger, NullLogger, State

Class Method Summary collapse

Class Method Details

.disable!Boolean

Disable MCP logging

Returns:

  • (Boolean)

    false



38
39
40
# File 'lib/action_mcp/logging.rb', line 38

def disable!
  state.disable!
end

.enable!Boolean

Enable MCP logging

Returns:

  • (Boolean)

    true



31
32
33
34
# File 'lib/action_mcp/logging.rb', line 31

def enable!
  ActionMCP.configuration.logging_enabled = true
  state.enable!
end

.enabled?Boolean

Check if logging is enabled

Returns:

  • (Boolean)

    true if enabled



25
26
27
# File 'lib/action_mcp/logging.rb', line 25

def enabled?
  ActionMCP.configuration.logging_enabled && state.enabled?
end

.initialize_from_config!Object

Initialize logging state based on configuration



82
83
84
85
86
87
88
89
90
91
# File 'lib/action_mcp/logging.rb', line 82

def self.initialize_from_config!
  # Always set the level from configuration
  state.level = ActionMCP.configuration.logging_level

  if ActionMCP.configuration.logging_enabled
    state.enable!
  else
    state.disable!
  end
end

.levelSymbol

Get the current minimum log level

Returns:

  • (Symbol)

    current level



44
45
46
# File 'lib/action_mcp/logging.rb', line 44

def level
  state.level_symbol
end

.level=(new_level) ⇒ Symbol Also known as: set_level

Set the minimum log level

Parameters:

  • new_level (String, Symbol, Integer)

    the new level

Returns:

  • (Symbol)

    the new level as symbol



51
52
53
54
# File 'lib/action_mcp/logging.rb', line 51

def level=(new_level)
  state.level = new_level
  state.level_symbol
end

.logger(name: nil, session:) ⇒ ActionMCP::Logging::Logger, ActionMCP::Logging::NullLogger

Create a logger for the given session

Parameters:

  • name (String, nil) (defaults to: nil)

    Optional logger name

  • session (ActionMCP::Session)

    The MCP session

Returns:



61
62
63
64
65
66
67
# File 'lib/action_mcp/logging.rb', line 61

def logger(name: nil, session:)
  if enabled?
    Logger.new(name: name, session: session, state: state)
  else
    NullLogger.new
  end
end

.logger_for_context(name: nil, execution_context:) ⇒ ActionMCP::Logging::Logger, ActionMCP::Logging::NullLogger

Convenience method to get a logger for the current session context

Parameters:

  • name (String, nil) (defaults to: nil)

    Optional logger name

  • execution_context (Hash)

    Context containing session

Returns:



73
74
75
76
77
78
# File 'lib/action_mcp/logging.rb', line 73

def logger_for_context(name: nil, execution_context:)
  session = execution_context[:session]
  return NullLogger.new unless session

  logger(name: name, session: session)
end

.reset!void

This method returns an undefined value.

Reset the global state (for testing)



19
20
21
# File 'lib/action_mcp/logging.rb', line 19

def reset!
  @state = State.new
end

.stateActionMCP::Logging::State

Get the global logging state

Returns:



13
14
15
# File 'lib/action_mcp/logging.rb', line 13

def state
  @state ||= State.new
end