Make sure that evaluation of the log block happens in the instance instead of class
Fixes #3
This commit is contained in:
parent
a0178aec34
commit
9df7b0b431
|
@ -5,3 +5,4 @@
|
|||
|
||||
* Add support for JMS-backed `Stapfen::Worker` classes
|
||||
* Deep copy the configuration passed into `Stomp::Client` to work-around [stomp #80](https://github.com/stompgem/stomp/issues/80)
|
||||
* Support per-instance log configuration [#3](https://github.com/lookout/stapfen/issues/3)
|
||||
|
|
|
@ -34,6 +34,11 @@ class MyWorker < Stapfen::Worker
|
|||
}
|
||||
end
|
||||
|
||||
# [Optional] Set up a logger for each worker instance
|
||||
log do
|
||||
Logger.new(STDOUT)
|
||||
end
|
||||
|
||||
consume 'thequeue', :dead_letter_queue => '/queue/dlq',
|
||||
:max_redeliveries => 0 do |message|
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ module Stapfen
|
|||
|
||||
def proxy_log_method(method, arguments)
|
||||
if self.logger
|
||||
self.logger.send(method, *arguments)
|
||||
self.logger.call.send(method, *arguments)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
|
@ -39,7 +39,7 @@ module Stapfen
|
|||
|
||||
def proxy_log_method(method, arguments)
|
||||
if self.class.logger
|
||||
self.class.logger.send(method, *arguments)
|
||||
self.class.logger.call.send(method, *arguments)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
|
|
|
@ -83,8 +83,8 @@ module Stapfen
|
|||
|
||||
# Optional method, should be passed a block which will yield a {{Logger}}
|
||||
# instance for the Stapfen worker to use
|
||||
def self.log
|
||||
@logger = yield
|
||||
def self.log(&block)
|
||||
@logger = block
|
||||
end
|
||||
|
||||
# Main message consumption block
|
||||
|
|
|
@ -29,7 +29,7 @@ describe Stapfen::Logger do
|
|||
let(:plogger) { double('RSpec Logger') }
|
||||
|
||||
before :each do
|
||||
logger.class.stub(:logger).and_return(plogger)
|
||||
logger.class.stub(:logger).and_return(lambda { plogger })
|
||||
end
|
||||
|
||||
it 'should pass info messages along' do
|
||||
|
|
|
@ -38,6 +38,22 @@ describe Stapfen::Worker do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#log' do
|
||||
it "should store the block it's passed" do
|
||||
logger = double('Mock Logger')
|
||||
|
||||
worker.log do
|
||||
logger
|
||||
end
|
||||
|
||||
expect(worker.logger).to be_instance_of Proc
|
||||
end
|
||||
|
||||
after :each do
|
||||
worker.logger = nil
|
||||
end
|
||||
end
|
||||
|
||||
describe '#configure' do
|
||||
it 'should error when not passed a block' do
|
||||
expect {
|
||||
|
@ -52,11 +68,10 @@ describe Stapfen::Worker do
|
|||
config
|
||||
end
|
||||
|
||||
worker.configuration.call.should == config
|
||||
expect(worker.configuration.call).to eql(config)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe '#exit_cleanly' do
|
||||
subject(:result) { worker.exit_cleanly }
|
||||
|
||||
|
|
Loading…
Reference in New Issue