Created
January 2, 2011 05:33
-
-
Save mcmire/762320 to your computer and use it in GitHub Desktop.
Writing `pp` output to a Rails log
This file contains 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
require 'pp' | |
module Kernel | |
class LoggerAppender | |
include Singleton | |
def <<(msg) | |
RAILS_DEFAULT_LOGGER.send(:buffer) << (msg || "") | |
RAILS_DEFAULT_LOGGER.send(:auto_flush) | |
msg | |
end | |
end | |
# pretty print to Rails log | |
def ppl(*objs) | |
logger.debug "\e[33m" | |
objs.each {|obj| | |
PP.pp(obj, LoggerAppender.instance) | |
} | |
logger.debug "\e[0m" | |
nil | |
end | |
module_function :ppl | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment