Class: Specwrk::Web::Logger
- Inherits:
-
Object
- Object
- Specwrk::Web::Logger
- Defined in:
- lib/specwrk/web/logger.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, out = $stdout, ignored_paths = []) ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
#initialize(app, out = $stdout, ignored_paths = []) ⇒ Logger
Returns a new instance of Logger.
6 7 8 9 10 |
# File 'lib/specwrk/web/logger.rb', line 6 def initialize(app, out = $stdout, ignored_paths = []) @app = app @out = out @ignored_paths = ignored_paths end |
Instance Method Details
#call(env) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/specwrk/web/logger.rb', line 12 def call(env) return @app.call(env) if @ignored_paths.include? env["PATH_INFO"] start_time = Time.now start = Process.clock_gettime(Process::CLOCK_MONOTONIC) status, headers, body = @app.call(env) dur_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1000).round(4) remote = env["REMOTE_ADDR"] || env["REMOTE_HOST"] || "-" worker_parts = [env["HTTP_X_SPECWRK_RUN"], env["HTTP_X_SPECWRK_ID"]].compact context = " #{worker_parts.join(" ")}" unless worker_parts.empty? @out.puts "#{remote} [#{start_time.iso8601(6)}] #{env["REQUEST_METHOD"]} #{env["PATH_INFO"]}#{context} → #{status} (#{dur_ms}ms)" [status, headers, body] end |