Skip to content

Commit

Permalink
Merge pull request postrank-labs#136 from radsaq/skip_logging2
Browse files Browse the repository at this point in the history
Add option to log to the null logger in the Heartbeat middleware
  • Loading branch information
igrigorik committed Jan 15, 2012
2 parents b3b4de1 + 98ae773 commit 8d3bde4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/goliath/rack/heartbeat.rb
Expand Up @@ -16,6 +16,8 @@ def initialize(app, opts = {})

def call(env)
if env['PATH_INFO'] == @opts[:path]
env[Goliath::Constants::RACK_LOGGER] = Log4r::Logger.root unless @opts[:log]

@opts[:response]
else
@app.call(env)
Expand Down
13 changes: 13 additions & 0 deletions spec/unit/rack/heartbeat_spec.rb
Expand Up @@ -52,6 +52,19 @@
headers.should == {}
body.should == nil
end

it 'does not log the request by default' do
@env['PATH_INFO'] = '/status'
@hb.call(@env)
@env[Goliath::Constants::RACK_LOGGER].should == Log4r::Logger.root
end

it 'logs the request only if asked' do
@env['PATH_INFO'] = '/status'
@hb = Goliath::Rack::Heartbeat.new(@app, :log => true)
@hb.call(@env)
@env[Goliath::Constants::RACK_LOGGER].should_not == Log4r::Logger.root
end
end
end

0 comments on commit 8d3bde4

Please sign in to comment.