Class: Wildcloud::Logger::Middleware::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/wildcloud/logger/middleware/console.rb

Constant Summary collapse

COLORS =
{:debug => "\e[36m", :info => "\e[32m", :warn => "\e[33m", :error => "\e[31m", :fatal => "\e[35m"}

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Console

Returns a new instance of Console.



23
24
25
26
27
28
29
# File 'lib/wildcloud/logger/middleware/console.rb', line 23

def initialize(app, options = {})
  @app = app
  @options = {
      :level_length => 8,
      :component_length => 10
  }.merge(options)
end

Instance Method Details

#call(msg) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/wildcloud/logger/middleware/console.rb', line 31

def call(msg)
  level = msg[:level]
  stdout = "#{COLORS[level]}#{level.to_s.rjust(@options[:level_length])}\e[0m"
  stdout << " (#{Time.at(msg[:timestamp])})"
  stdout << " :"
  stdout << " #{msg[:application]}" if msg[:application]
  stdout << " :"
  stdout << " #{msg[:component].to_s.ljust(@options[:component_length])}" if msg[:component]
  stdout << " :"
  stdout << " #{msg[:message]}"
  stdout << "\n"
  $stdout << stdout
  @app.call(msg)
end