Class: Wildcloud::Logger::Middleware::Console
- Inherits:
-
Object
- Object
- Wildcloud::Logger::Middleware::Console
- 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
- #call(msg) ⇒ Object
-
#initialize(app, options = {}) ⇒ Console
constructor
A new instance of Console.
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, = {}) @app = app @options = { :level_length => 8, :component_length => 10 }.merge() 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 |