Class: Rack::LogProxy
- Inherits:
-
Object
- Object
- Rack::LogProxy
- Defined in:
- lib/rack/simple_logger/log_proxy.rb
Instance Method Summary collapse
-
#initialize(logger) ⇒ LogProxy
constructor
A new instance of LogProxy.
- #write(log_hash) ⇒ Object
- #write_logger(log_hash) ⇒ Object
- #write_mongo(log_hash) ⇒ Object
- #write_other(log_hash) ⇒ Object
Constructor Details
#initialize(logger) ⇒ LogProxy
Returns a new instance of LogProxy.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rack/simple_logger/log_proxy.rb', line 5 def initialize(logger) case logger.class.to_s when "Logger" @logger = logger @log_type = :logger when "String", "IO" @logger = ::Logger.new(logger) @log_type = :logger when "Mongo::Collection" @logger = logger @log_type = :mongo else @logger = logger @log_type = :other end logger_formatter if @log_type == :logger end |
Instance Method Details
#write(log_hash) ⇒ Object
24 25 26 |
# File 'lib/rack/simple_logger/log_proxy.rb', line 24 def write(log_hash) send("write_#{@log_type}", log_hash) end |
#write_logger(log_hash) ⇒ Object
28 29 30 |
# File 'lib/rack/simple_logger/log_proxy.rb', line 28 def write_logger(log_hash) @logger.info log_hash.map{|k,v| [k, v].join(":")}.join("\t") end |
#write_mongo(log_hash) ⇒ Object
32 33 34 |
# File 'lib/rack/simple_logger/log_proxy.rb', line 32 def write_mongo(log_hash) @logger.insert log_hash end |
#write_other(log_hash) ⇒ Object
36 37 38 |
# File 'lib/rack/simple_logger/log_proxy.rb', line 36 def write_other(log_hash) @logger.write log_hash end |