Class: Footnotes::Notes::LogNote::NoteLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/rails-footnotes/notes/log_note/note_logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logs) ⇒ NoteLogger

Returns a new instance of NoteLogger.



6
7
8
# File 'lib/rails-footnotes/notes/log_note/note_logger.rb', line 6

def initialize(logs)
  @logs = logs
end

Class Method Details

.broadcast(logger) ⇒ Object

Broadcasts logs to multiple loggers.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rails-footnotes/notes/log_note/note_logger.rb', line 22

def self.broadcast(logger) # :nodoc:
  Module.new do
    define_method(:add) do |*args, &block|
      logger.add(*args, &block)
      super(*args, &block)
    end

    define_method(:<<) do |x|
      logger << x
      super(x)
    end

    define_method(:close) do
      logger.close
      super()
    end

    define_method(:progname=) do |name|
      logger.progname = name
      super(name)
    end

    define_method(:formatter=) do |formatter|
      logger.formatter = formatter
      super(formatter)
    end

    define_method(:level=) do |level|
      logger.level = level
      super(level)
    end
  end
end

Instance Method Details

#add(severity, message = nil, progname = nil, &block) ⇒ Object



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

def add(severity, message = nil, progname = nil, &block)
  severity ||= UNKNOWN
  if severity < level
    return true
  end
  formatter = @formatter || Logger::Formatter.new
  @logs << formatter.call(format_severity(severity), Time.now, message, progname)
end