Created
July 21, 2020 01:17
-
-
Save sankalpk/ac6b2684c9aed825195cdaf071fe5dfc to your computer and use it in GitHub Desktop.
Log Constants
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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