lib/semantic_logger/processor.rb in semantic_logger-4.2.0 vs lib/semantic_logger/processor.rb in semantic_logger-4.2.1
- old
+ new
@@ -58,12 +58,12 @@
# Allow the internal logger to be overridden from its default of STDERR
# Can be replaced with another Ruby logger or Rails logger, but never to
# SemanticLogger::Logger itself since it is for reporting problems
# while trying to log to the various appenders
- def self.logger=(logger)
- @logger = logger
+ class << self
+ attr_writer :logger
end
# Internal logger for SemanticLogger
# For example when an appender is not working etc..
# By default logs to STDERR
@@ -84,11 +84,14 @@
end
def on_log(object = nil, &block)
subscriber = block || object
- raise('When supplying an on_log subscriber, it must support the #call method') unless subscriber.is_a?(Proc) || subscriber.respond_to?(:call)
+ unless subscriber.is_a?(Proc) || subscriber.respond_to?(:call)
+ raise('When supplying an on_log subscriber, it must support the #call method')
+ end
+
subscribers = (@log_subscribers ||= Concurrent::Array.new)
subscribers << subscriber unless subscribers.include?(subscriber)
end
def log(log)
@@ -128,17 +131,15 @@
end
private
def self.create_instance
- SemanticLogger::Appender::Async.new(
- name: 'SemanticLogger::Processor',
- appender: new,
- max_queue_size: -1
- )
+ SemanticLogger::Appender::Async.new(appender: new, max_queue_size: -1)
end
+ private_class_method :create_instance
+
@processor = create_instance
# Call on_log subscribers
def call_log_subscribers(log)
# If no subscribers registered, then return immediately
@@ -150,8 +151,7 @@
rescue Exception => exc
logger.error 'Exception calling :on_log subscriber', exc
end
end
end
-
end
end