Skip to content

Instantly share code, notes, and snippets.

@jlindley
Created July 7, 2010 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlindley/466871 to your computer and use it in GitHub Desktop.
Save jlindley/466871 to your computer and use it in GitHub Desktop.
# 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