class Rack::DeltacloudLogger

Rack::CommonLogger forwards every request to an app given, and logs a line in the Apache common log format to the logger, or rack.errors by default.

Constants

FORMAT

Common Log Format: httpd.apache.org/docs/1.3/logs.html#common lilith.local - - [07/Aug/2006 23:58:02] "GET / HTTP/1.1" 500 -

%{%s - %s [%s] "%s %s%s %s" %d %s\n} %
VERBOSE_FORMAT

Public Class Methods

log_path(path=nil) click to toggle source
# File lib/sinatra/rack_logger.rb, line 30
def log_path(path=nil)
  @log_file ||= path
end
logger() click to toggle source
# File lib/sinatra/rack_logger.rb, line 54
def logger
  @logger ||= ::Logger.new(log_path || $stdout)
end
new(app, logger=nil) click to toggle source

If Deltacloud is started with the -L/--log option then we set logger to this file, otherwise use the default Sinatra logger facility

# File lib/sinatra/rack_logger.rb, line 76
def initialize(app, logger=nil)
  @app = app
  if self.class.log_path
    @logger = self.class.logger
  else
    @logger = logger
  end
end
setup(path, be_verbose=false) click to toggle source
# File lib/sinatra/rack_logger.rb, line 42
def setup(path, be_verbose=false)
  verbose(be_verbose)
  return self if path.nil?
  dir = ::File.dirname(path)
  if ::File.exists?(dir) and ::File.writable?(dir)
    log_path(path)
  else
    warn "Warning: The log directory (#{dir}) is not writeable."
  end
  self
end
verbose(v=nil) click to toggle source
# File lib/sinatra/rack_logger.rb, line 38
def verbose(v=nil)
  @verbose ||= v
end
verbose?() click to toggle source
# File lib/sinatra/rack_logger.rb, line 34
def verbose?
  @verbose
end

Public Instance Methods

call(env) click to toggle source
# File lib/sinatra/rack_logger.rb, line 85
def call(env)
  began_at = Time.now
  status, header, body = @app.call(env)
  header = Utils::HeaderHash.new(header)
  body = BodyProxy.new(body) do
    self.class.verbose? ? verbose_log(env, status, header, began_at) : log(env, status, header, began_at)
  end
  [status, header, body]
end