I am using Ruby on Rails 3.2.2 and, in order to display warning messages for development purposes, I am using logger.warn
in my code. I would like to retrieve the method name in which that logger.warn
runs so to output that method name to the log file.
class ClassName < ActiveRecord::Base
def method_name
# Note: This code doesn't work. It is just a sample.
logger.warn "I would like to retrieve and display the #{self.class.to_s}##{method_name}"
end
end
In the log file I would like to see:
I would like to retrieve and display the ClassName#method_name
Is it possible? If so, how can I make that?
class ClassName < ActiveRecord::Base
def method_name
logger.warn("I would like to retrieve and display the #{self.class}##{__method__}")
end
end
this should do the job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With