Class: Deas::BaseLogging
- Inherits:
-
Object
- Object
- Deas::BaseLogging
- Defined in:
- lib/deas/logging.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#call(env) ⇒ Object
The Rack call interface.
-
#call!(env) ⇒ Object
The real Rack call interface.
-
#initialize(app) ⇒ BaseLogging
constructor
A new instance of BaseLogging.
- #log(message) ⇒ Object
- #log_error(exception) ⇒ Object
Constructor Details
#initialize(app) ⇒ BaseLogging
Returns a new instance of BaseLogging.
14 15 16 17 |
# File 'lib/deas/logging.rb', line 14 def initialize(app) @app = app @logger = @app.settings.logger end |
Instance Method Details
#call(env) ⇒ Object
The Rack call interface. The receiver acts as a prototype and runs each request in a clone object unless the rack.run_once
variable is set in the environment. Ripped from: github.com/rtomayko/rack-cache/blob/master/lib/rack/cache/context.rb
23 24 25 26 27 28 29 |
# File 'lib/deas/logging.rb', line 23 def call(env) if env['rack.run_once'] call! env else clone.call! env end end |
#call!(env) ⇒ Object
The real Rack call interface. This is the common behavior for both the verbose and summary logging middlewares. It times the response and returns it as is.
34 35 36 37 38 39 40 41 42 |
# File 'lib/deas/logging.rb', line 34 def call!(env) status, headers, body = nil, nil, nil benchmark = Benchmark.measure do status, headers, body = @app.call(env) end log_error(env['sinatra.error']) env['deas.time_taken'] = RoundedTime.new(benchmark.real) [ status, headers, body ] end |
#log(message) ⇒ Object
44 45 46 |
# File 'lib/deas/logging.rb', line 44 def log() @logger.info "[Deas] #{}" end |
#log_error(exception) ⇒ Object
48 49 50 51 52 |
# File 'lib/deas/logging.rb', line 48 def log_error(exception) return if !exception || exception.kind_of?(Sinatra::NotFound) log "#{exception.class}: #{exception.}\n" \ "#{exception.backtrace.join("\n")}" end |