Add rails log to console
if ENV.include?('RAILS_ENV')&& !Object.const_defined?('RAILS_DEFAULT_LOGGER') Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(SDTOUT)) end
DZone Snippets > Mickael > log
12390 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
if ENV.include?('RAILS_ENV')&& !Object.const_defined?('RAILS_DEFAULT_LOGGER') Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(SDTOUT)) end
def log_to(stream) ActiveRecord::Base.logger = Logger.new(stream) ActiveRecord::Base.clear_active_connections! end
>> log_to STDOUT => ... >> Post.find(:first) Post Load (0.000138) SELECT * FROM posts LIMIT 1 => #<Post:0x1234 ...> >>
>> buffer = StringIO.new => ... >> log_to buffer => ... >> Post.find(:first) => #<Post:0x1234 ...> >> p buffer.string => " \e[4;35;1mPost Load (0.000138)\e[0m \e[0mSELECT * FROM posts LIMIT 1\e[0m\n" >>