Class: BrainzLab::Development::Logger

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

Overview

Pretty-prints development mode events to stdout

Constant Summary collapse

COLORS =

ANSI color codes

{
  reset: "\e[0m",
  bold: "\e[1m",
  dim: "\e[2m",
  # Services
  recall: "\e[36m",     # Cyan
  reflex: "\e[31m",     # Red
  pulse: "\e[33m",      # Yellow
  flux: "\e[35m",       # Magenta
  signal: "\e[32m",     # Green
  vault: "\e[34m",      # Blue
  vision: "\e[95m",     # Light magenta
  cortex: "\e[96m",     # Light cyan
  beacon: "\e[92m",     # Light green
  nerve: "\e[93m",      # Light yellow
  dendrite: "\e[94m",   # Light blue
  sentinel: "\e[91m",   # Light red
  synapse: "\e[97m",    # White
  # Log levels
  debug: "\e[37m",      # Gray
  info: "\e[32m",       # Green
  warn: "\e[33m",       # Yellow
  error: "\e[31m",      # Red
  fatal: "\e[35m"       # Magenta
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(output: $stdout, colors: nil) ⇒ Logger

Returns a new instance of Logger.



36
37
38
39
# File 'lib/brainzlab/development/logger.rb', line 36

def initialize(output: $stdout, colors: nil)
  @output = output
  @colors = colors.nil? ? tty? : colors
end

Instance Method Details

#log(service:, event_type:, payload:) ⇒ Object

Log an event to stdout in a readable format

Parameters:

  • service (Symbol)

    :recall, :reflex, :pulse, etc.

  • event_type (String)

    type of event

  • payload (Hash)

    event data



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/brainzlab/development/logger.rb', line 45

def log(service:, event_type:, payload:)
  timestamp = Time.now.strftime('%H:%M:%S.%L')
  service_color = COLORS[service] || COLORS[:reset]

  # Build the log line
  parts = []
  parts << colorize("[#{timestamp}]", :dim)
  parts << colorize("[#{service.to_s.upcase}]", service_color, bold: true)
  parts << colorize(event_type, :bold)

  # Add message or name depending on event type
  message = extract_message(payload, event_type)
  parts << message if message

  # Print the main line
  @output.puts parts.join(' ')

  # Print additional details indented
  print_details(payload, event_type)
end