Class: Footnotes::Notes::LogNote

Inherits:
AbstractNote show all
Defined in:
lib/rails-footnotes/notes/log_note.rb,
lib/rails-footnotes/notes/log_note/note_logger.rb

Defined Under Namespace

Classes: NoteLogger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractNote

close!, #escape, #has_fieldset?, #hash_to_xml_attributes, included?, #initialize, #javascript, #legend, #link, #mount_table, #mount_table_for_hash, #onclick, #prefix?, #row, #stylesheet, title, #to_sym, to_sym, #valid?

Constructor Details

This class inherits a constructor from Footnotes::Notes::AbstractNote

Class Method Details

.start!(controller) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/rails-footnotes/notes/log_note.rb', line 10

def self.start!(controller)
  self.logs = []
  self.original_logger = Rails.logger
  note_logger = NoteLogger.new(self.logs)
  note_logger.level = self.original_logger.level
  note_logger.formatter = self.original_logger.kind_of?(Logger) ? self.original_logger.formatter : ActiveSupport::Logger::SimpleFormatter.new
  # Rails 3 don't have ActiveSupport::Logger#broadcast so we backported it
  extend_module = defined?(ActiveSupport::Logger) ? ActiveSupport::Logger.broadcast(note_logger) : NoteLogger.broadcast(note_logger)
  Rails.logger = self.original_logger.dup.extend(extend_module)
end

Instance Method Details

#contentObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/rails-footnotes/notes/log_note.rb', line 25

def content
  result = '<table>'
    log.compact.each do |l|
      result << "<tr><td>#{l.gsub(/\e\[.+?m/, '')}</td></tr>"
    end
  result << '</table>'
  # Restore formatter
  Rails.logger = self.class.original_logger
  result
end

#logObject



36
37
38
# File 'lib/rails-footnotes/notes/log_note.rb', line 36

def log
  self.class.logs
end

#titleObject



21
22
23
# File 'lib/rails-footnotes/notes/log_note.rb', line 21

def title
  "Log (#{log.count})"
end