Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Commit

Permalink
Fix context checking
Browse files Browse the repository at this point in the history
  • Loading branch information
binarylogic committed Sep 4, 2016
1 parent f1f4f07 commit 617282a
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 22 deletions.
21 changes: 1 addition & 20 deletions lib/timber/current_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ module Timber
# Holds the current context in the current thread's memory.
# This context gets copied as each log line is written.
class CurrentContext
class ContextAlreadyAddedError < StandardError
def initialize(context)
super("Context of type #{context.class.name} has already been added: #{context.as_json.inspect}")
end
end

THREAD_NAMESPACE = :_timber_current_context.freeze
STACK_KEYNAME = :stack.freeze
PRECISION = 8.freeze
Expand All @@ -20,11 +14,7 @@ def initialize(context)
def add(*contexts, &_block)
contexts = contexts.compact
contexts.each do |context|
if include?(context)
raise ContextAlreadyAddedError.new(context)
else
stack << context
end
stack << context
end
block_given? ? yield : self
ensure
Expand All @@ -36,15 +26,6 @@ def get(type)
stack.find { |context| context.is_a?(type) }
end

# Check if any of the contexts have already been added.
# The context stack is a unique set of context types, so we
# check the class type only.
def include?(context)
stack.any? do |current_context|
current_context.class == context.class
end
end

# Removes the contexts from the current stack.
def remove(*contexts)
# Ensure we clear the cacke when the stack changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Probes
class ActiveSupportLogSubscriber < Probe
module ActiveRecord
def self.sql(log_subscriber, event, &_block)
Config.logger.warn("Adding sql context for #{event.payload[:sql]}")
context1 = Contexts::SQLQueries::ActiveRecord.new(log_subscriber, event)
context2 = Contexts::SQLQueries::ActiveRecordSpecific.new(log_subscriber, event)
CurrentContext.add(context1, context2) { yield }
Expand Down
1 change: 0 additions & 1 deletion lib/timber/probes/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def add(level, *args, &block)
_timber_old_add(level, *args, &block)
else
context = Contexts::Logger.new(level, progname)
Config.logger.warn("Adding logger for #{level} #{args.inspect}")
CurrentContext.add(context) do
_timber_old_add(level, *args, &block)
end
Expand Down

0 comments on commit 617282a

Please sign in to comment.