lib/prefab/internal_logger.rb in prefab-cloud-ruby-1.5.1 vs lib/prefab/internal_logger.rb in prefab-cloud-ruby-1.6.0.pre1
- old
+ new
@@ -1,16 +1,42 @@
-# frozen_string_literal: true
-
module Prefab
- class InternalLogger < StaticLogger
- INTERNAL_PREFIX = 'cloud.prefab.client'
+ class InternalLogger < SemanticLogger::Logger
- def initialize(path)
- if path.is_a?(Class)
- path_string = path.name.split('::').last.downcase
- else
- path_string = path
+ def initialize(klass)
+ super(klass, :warn)
+ instances << self
+ end
+
+ def log(log, message = nil, progname = nil, &block)
+ return if recurse_check[local_log_id]
+ recurse_check[local_log_id] = true
+ begin
+ super(log, message, progname, &block)
+ ensure
+ recurse_check[local_log_id] = false
end
- super("#{INTERNAL_PREFIX}.#{path_string}")
+ end
+
+ def local_log_id
+ Thread.current.__id__
+ end
+
+ # Our client outputs debug logging,
+ # but if you aren't using Prefab logging this could be too chatty.
+ # If you aren't using prefab log filter, only log warn level and above
+ def self.using_prefab_log_filter!
+ @@instances.each do |l|
+ l.level = :trace
+ end
+ end
+
+ private
+
+ def instances
+ @@instances ||= []
+ end
+
+ def recurse_check
+ @recurse_check ||=Concurrent::Map.new(initial_capacity: 2)
end
end
end