Class: Rack::DeltacloudLogger
- Inherits:
-
Object
- Object
- Rack::DeltacloudLogger
- 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
- .error(code, &block) ⇒ Object
- .log_path(path = nil) ⇒ Object
- .setup(path, be_verbose = false) ⇒ Object
- .verbose(v = nil) ⇒ Object
- .verbose? ⇒ Boolean
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, logger = nil) ⇒ DeltacloudLogger
constructor
A new instance of DeltacloudLogger.
Constructor Details
#initialize(app, logger = nil) ⇒ DeltacloudLogger
Returns a new instance of DeltacloudLogger.
65 66 67 68 69 70 71 72 |
# File 'lib/sinatra/rack_logger.rb', line 65 def initialize(app, logger=nil) @app = app unless self.class.log_path.nil? @logger = ::Logger.new(self.class.log_path) else @logger = logger end end |
Class Method Details
.error(code, &block) ⇒ Object
53 54 55 56 |
# File 'lib/sinatra/rack_logger.rb', line 53 def self.error(code, &block) @logger ||= ::Logger.new(log_path || $stdout) @logger.error(code, &block) end |
.log_path(path = nil) ⇒ Object
29 30 31 |
# File 'lib/sinatra/rack_logger.rb', line 29 def self.log_path(path=nil) @log_file ||= path end |
.setup(path, be_verbose = false) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sinatra/rack_logger.rb', line 41 def self.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
37 38 39 |
# File 'lib/sinatra/rack_logger.rb', line 37 def self.verbose(v=nil) @verbose ||= v end |
.verbose? ⇒ Boolean
33 34 35 |
# File 'lib/sinatra/rack_logger.rb', line 33 def self.verbose? @verbose end |
Instance Method Details
#call(env) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/sinatra/rack_logger.rb', line 74 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 |