Module: Ukiryu::Debug

Defined in:
lib/ukiryu/debug.rb

Overview

Debug utility for conditional debug logging

Provides a single point of control for debug logging across the codebase. Debug logging is only enabled when UKIRYU_DEBUG environment variable is set.

Examples:

Enable debug logging

ENV['UKIRYU_DEBUG'] = '1'
Ukiryu.debug_enabled? # => true

Disable debug logging (default)

Ukiryu.debug_enabled? # => false

Log with category

Ukiryu::Debug.log("Found executable", category: :executable)

Class Method Summary collapse

Class Method Details

.enabled?(category = nil) ⇒ Boolean

Check if debug logging is enabled for a category

Parameters:

  • category (Symbol, nil) (defaults to: nil)

    the category (:executable for UKIRYU_DEBUG_EXECUTABLE)

Returns:

  • (Boolean)

    true if debug mode is enabled



24
25
26
27
28
29
30
31
# File 'lib/ukiryu/debug.rb', line 24

def enabled?(category = nil)
  case category
  when :executable
    ENV['UKIRYU_DEBUG_EXECUTABLE'] || (defined?(Platform) && Platform.windows? && ENV['CI'])
  else
    ENV['UKIRYU_DEBUG'] || ENV['UKIRYU_DEBUG_EXECUTABLE']
  end
end

.log(message, category: nil, context: {}) ⇒ Object

Log a debug message to stderr

Parameters:

  • message (String)

    the debug message

  • category (Symbol, nil) (defaults to: nil)

    optional category (:executable for executable discovery)

  • context (Hash) (defaults to: {})

    optional context data



38
39
40
41
42
43
44
# File 'lib/ukiryu/debug.rb', line 38

def log(message, category: nil, context: {})
  return unless enabled?(category)

  prefix = "[UKIRYU DEBUG#{category ? " #{category.to_s.upcase}" : ''}]"
  details = context.empty? ? '' : " (#{context.map { |k, v| "#{k}=#{v.inspect}" }.join(', ')})"
  warn "#{prefix} #{message}#{details}"
end