You can monkey patch the BufferedLogger to do what you want. Put this file in your config/initializers
path:
require 'active_support/buffered_logger'
class ActiveSupport::BufferedLogger
def add(severity, message = nil, progname = nil, &block)
add_debugging_details(severity)
@log.add(severity, message, progname, &block)
end
private
EXCLUDE_CALLERS = Gem.paths.path.clone << 'script/rails' << RbConfig::CONFIG['rubylibdir'] << __FILE__
def add_debugging_details(severity)
caller_in_app = caller.select do |line|
EXCLUDE_CALLERS.detect { |gem_path| line.starts_with?(gem_path) }.nil?
end
return if caller_in_app.empty?
@log.add(severity, "Your code in \e[1;33m#{caller_in_app.first}\e[0;0m triggered:")
end
end if Rails.env.development?