Created
November 8, 2011 07:32
-
-
Save cpetschnig/1347225 to your computer and use it in GitHub Desktop.
Trace the origin of your Rails logging output
This file contains hidden or 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
class ActiveSupport::BufferedLogger | |
def add(severity, message = nil, progname = nil, &block) | |
return if @level > severity | |
message = (message || (block && block.call) || progname).to_s | |
# If a newline is necessary then create a new message ending with a newline. | |
# Ensures that the original message is not mutated. | |
message = "#{message}\n" unless message[-1] == ?\n | |
buffer << message | |
# <additional_debugging_output> | |
if @level == DEBUG | |
project_path = '/Users/cpetschnig/Projects' # increase readability | |
ruby_lib_path_fragment = 'ruby-enterprise' # just any significant part of the path to your installed gems | |
buffer << caller.reject{|x| x.include?(ruby_lib_path_fragment) || x.starts_with?('script/rails') || x.include?('infopark_base_query_cache.rb')}[0,3].map{|x| " *** #{x.starts_with?(project_path) ? x.sub(project_path, '...') : x}\n"}.join | |
end | |
# </additional_debugging_output> | |
auto_flush | |
message | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment