Deletes logging from AS::Dependencies
This commit is contained in:
parent
df41acdad9
commit
dc7817cb42
@ -86,12 +86,6 @@ def self.unload_interlock
|
|||||||
# to allow arbitrary constants to be marked for unloading.
|
# to allow arbitrary constants to be marked for unloading.
|
||||||
mattr_accessor :explicitly_unloadable_constants, default: []
|
mattr_accessor :explicitly_unloadable_constants, default: []
|
||||||
|
|
||||||
# The logger used when tracing autoloads.
|
|
||||||
mattr_accessor :logger
|
|
||||||
|
|
||||||
# If true, trace autoloads with +logger.debug+.
|
|
||||||
mattr_accessor :verbose, default: false
|
|
||||||
|
|
||||||
# The WatchStack keeps a stack of the modules being watched as files are
|
# The WatchStack keeps a stack of the modules being watched as files are
|
||||||
# loaded. If a file in the process of being loaded (parent.rb) triggers the
|
# loaded. If a file in the process of being loaded (parent.rb) triggers the
|
||||||
# load of another file (child.rb) the stack will ensure that child.rb
|
# load of another file (child.rb) the stack will ensure that child.rb
|
||||||
@ -474,7 +468,6 @@ def autoload_module!(into, const_name, qualified_name, path_suffix)
|
|||||||
return nil unless base_path = autoloadable_module?(path_suffix)
|
return nil unless base_path = autoloadable_module?(path_suffix)
|
||||||
mod = Module.new
|
mod = Module.new
|
||||||
into.const_set const_name, mod
|
into.const_set const_name, mod
|
||||||
log("constant #{qualified_name} autoloaded (module autovivified from #{File.join(base_path, path_suffix)})")
|
|
||||||
autoloaded_constants << qualified_name unless autoload_once_paths.include?(base_path)
|
autoloaded_constants << qualified_name unless autoload_once_paths.include?(base_path)
|
||||||
autoloaded_constants.uniq!
|
autoloaded_constants.uniq!
|
||||||
mod
|
mod
|
||||||
@ -532,7 +525,6 @@ def load_missing_constant(from_mod, const_name)
|
|||||||
require_or_load(expanded, qualified_name)
|
require_or_load(expanded, qualified_name)
|
||||||
|
|
||||||
if from_mod.const_defined?(const_name, false)
|
if from_mod.const_defined?(const_name, false)
|
||||||
log("constant #{qualified_name} autoloaded from #{expanded}.rb")
|
|
||||||
return from_mod.const_get(const_name)
|
return from_mod.const_get(const_name)
|
||||||
else
|
else
|
||||||
raise LoadError, "Unable to autoload constant #{qualified_name}, expected #{file_path} to define it"
|
raise LoadError, "Unable to autoload constant #{qualified_name}, expected #{file_path} to define it"
|
||||||
@ -585,7 +577,6 @@ def load_missing_constant(from_mod, const_name)
|
|||||||
# as the environment will be in an inconsistent state, e.g. other constants
|
# as the environment will be in an inconsistent state, e.g. other constants
|
||||||
# may have already been unloaded and not accessible.
|
# may have already been unloaded and not accessible.
|
||||||
def remove_unloadable_constants!
|
def remove_unloadable_constants!
|
||||||
log("removing unloadable constants")
|
|
||||||
autoloaded_constants.each { |const| remove_constant const }
|
autoloaded_constants.each { |const| remove_constant const }
|
||||||
autoloaded_constants.clear
|
autoloaded_constants.clear
|
||||||
explicitly_unloadable_constants.each { |const| remove_constant const }
|
explicitly_unloadable_constants.each { |const| remove_constant const }
|
||||||
@ -732,10 +723,6 @@ def remove_constant(const) #:nodoc:
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def log(message)
|
|
||||||
logger.debug("autoloading: #{message}") if logger && verbose
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
def uninitialized_constant(qualified_name, const_name, receiver:)
|
def uninitialized_constant(qualified_name, const_name, receiver:)
|
||||||
NameError.new("uninitialized constant #{qualified_name}", const_name, receiver: receiver)
|
NameError.new("uninitialized constant #{qualified_name}", const_name, receiver: receiver)
|
||||||
|
@ -1147,52 +1147,3 @@ def test_load_and_require_stay_private
|
|||||||
ActiveSupport::Dependencies.hook!
|
ActiveSupport::Dependencies.hook!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class DependenciesLogging < ActiveSupport::TestCase
|
|
||||||
MESSAGE = "message"
|
|
||||||
|
|
||||||
def with_settings(logger, verbose)
|
|
||||||
original_logger = ActiveSupport::Dependencies.logger
|
|
||||||
original_verbose = ActiveSupport::Dependencies.verbose
|
|
||||||
|
|
||||||
ActiveSupport::Dependencies.logger = logger
|
|
||||||
ActiveSupport::Dependencies.verbose = verbose
|
|
||||||
|
|
||||||
yield
|
|
||||||
ensure
|
|
||||||
ActiveSupport::Dependencies.logger = original_logger
|
|
||||||
ActiveSupport::Dependencies.verbose = original_verbose
|
|
||||||
end
|
|
||||||
|
|
||||||
def fake_logger
|
|
||||||
Class.new do
|
|
||||||
def self.debug(message)
|
|
||||||
message
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "does not log if the logger is nil and verbose is false" do
|
|
||||||
with_settings(nil, false) do
|
|
||||||
assert_nil ActiveSupport::Dependencies.log(MESSAGE)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "does not log if the logger is nil and verbose is true" do
|
|
||||||
with_settings(nil, true) do
|
|
||||||
assert_nil ActiveSupport::Dependencies.log(MESSAGE)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "does not log if the logger is set and verbose is false" do
|
|
||||||
with_settings(fake_logger, false) do
|
|
||||||
assert_nil ActiveSupport::Dependencies.log(MESSAGE)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "logs if the logger is set and verbose is true" do
|
|
||||||
with_settings(fake_logger, true) do
|
|
||||||
assert_equal "autoloading: #{MESSAGE}", ActiveSupport::Dependencies.log(MESSAGE)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
@ -334,42 +334,6 @@ def once_autoloader.reload
|
|||||||
assert_equal %i(main_autoloader), $zeitwerk_integration_reload_test
|
assert_equal %i(main_autoloader), $zeitwerk_integration_reload_test
|
||||||
end
|
end
|
||||||
|
|
||||||
test "verbose = true sets the dependencies logger if present" do
|
|
||||||
boot
|
|
||||||
|
|
||||||
logger = Logger.new(File::NULL)
|
|
||||||
ActiveSupport::Dependencies.logger = logger
|
|
||||||
ActiveSupport::Dependencies.verbose = true
|
|
||||||
|
|
||||||
Rails.autoloaders.each do |autoloader|
|
|
||||||
assert_same logger, autoloader.logger
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "verbose = true sets the Rails logger as fallback" do
|
|
||||||
boot
|
|
||||||
|
|
||||||
ActiveSupport::Dependencies.verbose = true
|
|
||||||
|
|
||||||
Rails.autoloaders.each do |autoloader|
|
|
||||||
assert_same Rails.logger, autoloader.logger
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "verbose = false sets loggers to nil" do
|
|
||||||
boot
|
|
||||||
|
|
||||||
ActiveSupport::Dependencies.verbose = true
|
|
||||||
Rails.autoloaders.each do |autoloader|
|
|
||||||
assert autoloader.logger
|
|
||||||
end
|
|
||||||
|
|
||||||
ActiveSupport::Dependencies.verbose = false
|
|
||||||
Rails.autoloaders.each do |autoloader|
|
|
||||||
assert_nil autoloader.logger
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "unhooks" do
|
test "unhooks" do
|
||||||
boot
|
boot
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user