Skip to content

Instantly share code, notes, and snippets.

@sankalpk
Created July 21, 2020 01:17
Show Gist options
  • Save sankalpk/ac6b2684c9aed825195cdaf071fe5dfc to your computer and use it in GitHub Desktop.
Save sankalpk/ac6b2684c9aed825195cdaf071fe5dfc to your computer and use it in GitHub Desktop.
Log Constants
#config/initializers/log_constants
module LogConstantLoading
@@log_depth = 0
def load_missing_constant(from_mod, const_name)
log_loading("load_missing_constant(#{from_mod}, #{const_name})") do
super
end
end
def remove_constant(const)
log_loading("remove_constant(#{const})") do
super
end
end
def log_loading(msg)
# Use `Rails.logger` instead of `puts`?
whitespace = " " * @@log_depth
puts whitespace + msg
@@log_depth += 1
result = yield
@@log_depth -= 1
puts whitespace + "(done) " + msg
result
end
end
ActiveSupport::Dependencies.module_eval do
class << self
prepend(LogConstantLoading)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment