Class: Rack::DeltacloudLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/rack_logger.rb

Overview

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.

Constant Summary collapse

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} %
%{%s - %s [%s] "%s %s%s %s" %d %s %0.4f\n}
VERBOSE_FORMAT =
%{%s - %s [%s] "%s %s%s%s %s" %s %s %d %s %0.4f\n}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, logger = nil) ⇒ DeltacloudLogger

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



76
77
78
79
80
81
82
83
# 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

Class Method Details

.log_path(path = nil) ⇒ Object



30
31
32
# File 'lib/sinatra/rack_logger.rb', line 30

def log_path(path=nil)
  @log_file ||= path
end

.loggerObject



54
55
56
# File 'lib/sinatra/rack_logger.rb', line 54

def logger
  @logger ||= ::Logger.new(log_path || $stdout)
end

.setup(path, be_verbose = false) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# 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) ⇒ Object



38
39
40
# File 'lib/sinatra/rack_logger.rb', line 38

def verbose(v=nil)
  @verbose ||= v
end

.verbose?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/sinatra/rack_logger.rb', line 34

def verbose?
  @verbose
end

Instance Method Details

#call(env) ⇒ Object



85
86
87
88
89
90
91
92
93
# 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