Skip to content

Commit

Permalink
Add ENV variable to debug zeitwerk with logging and eager loading
Browse files Browse the repository at this point in the history
It's far easier to debug in dev/test/containers using an ENV variable
so we'll make it so zeitwerk stdout logging and eager loading of all engines
is only done with this flag enabled.
  • Loading branch information
jrafanie committed Aug 10, 2023
1 parent 2d41202 commit a6a79f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ class Application < Rails::Application
Vmdb::Loggers.apply_config(::Settings.log)
end

initializer :eager_load_all_the_things, :after => :load_config_initializers do
if ENV['DEBUG_MANAGEIQ_ZEITWERK'].present?
config.eager_load_paths += config.autoload_paths
Vmdb::Plugins.each do |plugin|
plugin.config.eager_load_paths += plugin.config.autoload_paths
end
end
end

config.after_initialize do
Vmdb::Initializer.init
ActiveRecord::Base.connection_pool.release_connection
Expand Down
5 changes: 5 additions & 0 deletions config/initializers/zeitwerk.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
if Rails.application.config.autoloader == :zeitwerk && Rails.autoloaders.main
if ENV['DEBUG_MANAGEIQ_ZEITWERK'].present?
Zeitwerk::Loader.default_logger = method(:puts)
Rails.autoloaders.main.logger = Logger.new($stdout)
end

# These specific directories are for code organization, not namespacing:
# TODO: these should be either renamed with good names, the intermediate directory removed
# and/or both.
Expand Down

0 comments on commit a6a79f8

Please sign in to comment.