Created
July 7, 2010 16:01
-
-
Save jlindley/466871 to your computer and use it in GitHub Desktop.
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
# Easily inspect any list of objects in logger. | |
# Provided as a hack to the standard ruby (or Rails) logger: | |
# | |
# Example Code: | |
# | |
# # in some_file.rb | |
# chicken = :fred | |
# all_the_birds = [chicken, :roadrunner] | |
# my_logger.inspector(chicken, all_the_birds) # outputs to log: | |
# | |
# Example Log Output: | |
# | |
# # in some.log | |
# Inspector from: /path/to/some_file.rb:4:in 'some_method' | |
# 0: :fred | |
# 1: [:fred, :roadrunner] | |
# | |
module LoggerInspector | |
def inspector(*objects) | |
out = "Inspector from: #{caller[0]}\n" | |
objects.each_with_index do |obj, index| | |
out << " #{index}: #{obj.inspect}\n" | |
end | |
out << "\n" | |
debug out | |
end | |
end | |
class ActiveSupport::BufferedLogger | |
include LoggerInspector | |
end | |
class Logger | |
include LoggerInspector | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment