lib/rails-footnotes/notes/log_note.rb in rails3-footnotes-4.0.0.pre.6 vs lib/rails-footnotes/notes/log_note.rb in rails3-footnotes-4.0.0.pre.7

- old
+ new

@@ -1,48 +1,49 @@ require "#{File.dirname(__FILE__)}/abstract_note" module Footnotes module Notes class LogNote < AbstractNote - @@log = [] + def self.logs + @@logs ||= [] + end + def self.log(message) - @@log << message + logs << message unless message =~ /SQL|SELECT/ end + def self.clear_logs + @@logs = [] + end + def initialize(controller) @controller = controller end + def start! + self.class.clear_logs + end + def title - "Log (#{log.count("\n")})" + "Log (#{self.class.logs.size})" end def content - escape(log.gsub(/\e\[.+?m/, '')).gsub("\n", '<br />') + self.class.logs.map do |l| + escape(l.gsub(/\e\[.+?m/, '')) + end.join('<br />') end - def log - unless @log - @log = @@log.join('') - @@log = [] - if rindex = @log.rindex('Processing '+@controller.class.name+'#'+@controller.action_name) - @log = @log[rindex..-1] - end - end - @log - end + end + end - # FIXME (andre 2011-04-04) Fix this to collect Rails 3 logs - module LoggingExtensions - def add(*args, &block) - logged_message = super - Footnotes::Notes::LogNote.log(logged_message) - logged_message - end - end - - Rails.logger.extend LoggingExtensions + module LoggingExtensions + def add(*args, &block) + message = super + Footnotes::Notes::LogNote.log(message) + message end end + end