How can I make this method, which outputs a yellow line in the log file, accessible from everywhere (Models, Controllers, Views) in my Rails app?
def my_log(text, file = "", line = "")
text.to_s.chomp.gsub!(/%/, "%%")
Rails.logger.debug(sprintf("\033[32m#{file}#{line}\033[0m\033[1m\033[33m#{text}\033[0m"))
end
You could define it in
Kernel(NOT recommended):… if you really want it available anywhere.
Or, place something like this in
lib/util.rb:… and make sure to
require 'util'in yourconfig/application.rband then you can call this anywhere: