Sha256: b8c7370795674e83e5123e144152db0ff9b0a0eb850f77ceeefb4987147b6373

Contents?: true

Size: 1.08 KB

Versions: 21

Compression:

Stored size: 1.08 KB

Contents

require "#{File.dirname(__FILE__)}/abstract_note"

module Footnotes
  module Notes
    class LogNote < AbstractNote
      def initialize(controller)
        @controller = controller
      end

      def content
        escape(log_tail).gsub("\n","<br />")
      end

      protected
        def log_tail
          filename = if RAILS_DEFAULT_LOGGER.instance_variable_get('@log')
            RAILS_DEFAULT_LOGGER.instance_variable_get('@log').path
          else 
            RAILS_DEFAULT_LOGGER.instance_variable_get('@logdev').filename
          end
          file_string = File.open(filename).read.to_s

          # We try to select the specified action from the log
          # If we can't find it, we get the last 100 lines
          #
          if rindex = file_string.rindex('Processing '+@controller.controller_class_name+'#'+@controller.action_name)
            file_string[rindex..-1].gsub(/\e\[.+?m/, '')
          else
            lines = file_string.split("\n")
            index = [lines.size-100,0].max
            lines[index..-1].join("\n")
          end
        end
    end
  end
end

Version data entries

21 entries across 21 versions & 7 rubygems

Version Path
artofmission-rails-footnotes-3.6.0.1 lib/rails-footnotes/notes/log_note.rb
artofmission-rails-footnotes-3.6.2 lib/rails-footnotes/notes/log_note.rb
ceritium-rails-footnotes-3.4.1.1 lib/rails-footnotes/notes/log_note.rb
ceritium-rails-footnotes-3.4.1 lib/rails-footnotes/notes/log_note.rb
ceritium-rails-footnotes-3.4 lib/rails-footnotes/notes/log_note.rb
josevalim-rails-footnotes-3.3.1 lib/notes/log_note.rb
josevalim-rails-footnotes-3.3.2 lib/notes/log_note.rb
josevalim-rails-footnotes-3.4.1 lib/rails-footnotes/notes/log_note.rb
josevalim-rails-footnotes-3.4 lib/rails-footnotes/notes/log_note.rb
josevalim-rails-footnotes-3.5.0 lib/rails-footnotes/notes/log_note.rb
josevalim-rails-footnotes-3.6.0 lib/rails-footnotes/notes/log_note.rb
josevalim-rails-footnotes-3.6.1 lib/rails-footnotes/notes/log_note.rb
josevalim-rails-footnotes-3.6.2 lib/rails-footnotes/notes/log_note.rb
lexrupy-rails-footnotes-3.3.2 lib/rails-footnotes/notes/log_note.rb
lexrupy-rails-footnotes-3.4.1 lib/rails-footnotes/notes/log_note.rb
lexrupy-rails-footnotes-3.4 lib/rails-footnotes/notes/log_note.rb
omghax-rails-footnotes-3.6.1 lib/rails-footnotes/notes/log_note.rb
omghax-rails-footnotes-3.6.2 lib/rails-footnotes/notes/log_note.rb
scharfie-rails-footnotes-3.5.0 lib/rails-footnotes/notes/log_note.rb
scharfie-rails-footnotes-3.4.2 lib/rails-footnotes/notes/log_note.rb