Module: SwarmSDK::V3::DebugLog
- Defined in:
- lib/swarm_sdk/v3/debug_log.rb
Overview
Lightweight debug logging for V3 agents
Activated by setting the ‘DEBUG` or `SWARM_DEBUG` environment variable. Outputs timestamped debug messages to stderr with timing information for performance profiling.
Class Method Summary collapse
-
.enabled? ⇒ Boolean
Whether debug logging is enabled.
-
.log(component, message) ⇒ void
Log a debug message to stderr.
-
.time(component, label) { ... } ⇒ Object
Execute a block and log its execution time.
Class Method Details
.enabled? ⇒ Boolean
Whether debug logging is enabled
22 23 24 25 26 |
# File 'lib/swarm_sdk/v3/debug_log.rb', line 22 def enabled? return @enabled if defined?(@enabled) @enabled = ENV["DEBUG"] == "1" || ENV["SWARM_DEBUG"] == "1" end |
.log(component, message) ⇒ void
This method returns an undefined value.
Log a debug message to stderr
36 37 38 39 40 41 |
# File 'lib/swarm_sdk/v3/debug_log.rb', line 36 def log(component, ) return unless enabled? = Time.now.strftime("%H:%M:%S.%L") warn("[DEBUG #{}] [#{component}] #{}") end |
.time(component, label) { ... } ⇒ Object
Execute a block and log its execution time
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/swarm_sdk/v3/debug_log.rb', line 54 def time(component, label) unless enabled? return yield end log(component, "#{label} START") start = Process.clock_gettime(Process::CLOCK_MONOTONIC) result = yield elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start log(component, "#{label} DONE (#{format_duration(elapsed)})") result end |