lib/rdkafka/config.rb in rdkafka-0.8.1 vs lib/rdkafka/config.rb in rdkafka-0.9.0

- old
+ new

@@ -9,18 +9,36 @@ @@logger = Logger.new(STDOUT) # @private @@statistics_callback = nil # @private @@opaques = {} + # @private + @@log_queue = Queue.new + Thread.start do + loop do + severity, msg = @@log_queue.pop + @@logger.add(severity, msg) + end + end + # Returns the current logger, by default this is a logger to stdout. # # @return [Logger] def self.logger @@logger end + # Returns a queue whose contents will be passed to the configured logger. Each entry + # should follow the format [Logger::Severity, String]. The benefit over calling the + # logger directly is that this is safe to use from trap contexts. + # + # @return [Queue] + def self.log_queue + @@log_queue + end + # Set the logger that will be used for all logging output by this library. # # @param logger [Logger] The logger to be used # # @return [nil] @@ -31,14 +49,14 @@ # Set a callback that will be called every time the underlying client emits statistics. # You can configure if and how often this happens using `statistics.interval.ms`. # The callback is called with a hash that's documented here: https://github.com/edenhill/librdkafka/blob/master/STATISTICS.md # - # @param callback [Proc] The callback + # @param callback [Proc, #call] The callback # # @return [nil] def self.statistics_callback=(callback) - raise TypeError.new("Callback has to be a proc or lambda") unless callback.is_a? Proc + raise TypeError.new("Callback has to be callable") unless callback.respond_to?(:call) @@statistics_callback = callback end # Returns the current statistics callback, by default this is nil. #