Class: Igor::Logger
- Inherits:
-
Object
- Object
- Igor::Logger
- Defined in:
- lib/igor/logger.rb
Constant Summary collapse
- PreFormat =
"Processing (%s %s %s) %s"
- PostFormat =
"Done (%s %s %s) in %0.4fs"
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(igor, logger = nil) ⇒ Logger
constructor
A new instance of Logger.
- #log_around(env) ⇒ Object
Constructor Details
#initialize(igor, logger = nil) ⇒ Logger
Returns a new instance of Logger.
3 4 5 6 |
# File 'lib/igor/logger.rb', line 3 def initialize(igor, logger=nil) @igor = igor @logger = logger end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 |
# File 'lib/igor/logger.rb', line 8 def call(env) log_around(env) { @igor.call(env) } end |
#log_around(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/igor/logger.rb', line 15 def log_around(env) logger = @logger || env['igor.errors'] header = env['igor.amqp.header'] start_time = Time.now logger.puts PreFormat % [ header.delivery_tag, header.exchange, header.routing_key, start_time.strftime("%Y-%m-%d %H:%M:%S") ] yield(env).tap {|response| logger.puts "rsp %s" % response.inspect now = Time.now logger.puts PostFormat % [ header.delivery_tag, header.exchange, header.routing_key, now-start_time ] } end |