mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
fix done not logging when using with_context in a worker
This commit is contained in:
parent
01dc468a22
commit
2d567ed340
2 changed files with 38 additions and 6 deletions
|
@ -17,12 +17,10 @@ module Sidekiq
|
|||
end
|
||||
|
||||
def self.with_context(msg)
|
||||
begin
|
||||
Thread.current[:sidekiq_context] = msg
|
||||
yield
|
||||
ensure
|
||||
Thread.current[:sidekiq_context] = nil
|
||||
end
|
||||
previous, Thread.current[:sidekiq_context] = Thread.current[:sidekiq_context], msg
|
||||
yield
|
||||
ensure
|
||||
Thread.current[:sidekiq_context] = previous
|
||||
end
|
||||
|
||||
def self.initialize_logger(log_target = STDOUT)
|
||||
|
|
34
test/test_logging.rb
Normal file
34
test/test_logging.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
require 'helper'
|
||||
require 'sidekiq/logging'
|
||||
|
||||
class TestFetcher < Sidekiq::Test
|
||||
describe Sidekiq::Logging do
|
||||
describe "#with_context" do
|
||||
def context
|
||||
Sidekiq::Logging.logger.formatter.context
|
||||
end
|
||||
|
||||
it "has no context by default" do
|
||||
context.must_equal ""
|
||||
end
|
||||
|
||||
it "can add a context" do
|
||||
Sidekiq::Logging.with_context "xx" do
|
||||
context.must_equal " xx"
|
||||
end
|
||||
context.must_equal ""
|
||||
end
|
||||
|
||||
it "can use multiple contexts" do
|
||||
Sidekiq::Logging.with_context "xx" do
|
||||
context.must_equal " xx"
|
||||
Sidekiq::Logging.with_context "yy" do
|
||||
context.must_equal " yy"
|
||||
end
|
||||
context.must_equal " xx"
|
||||
end
|
||||
context.must_equal ""
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue