Class: LogEasy::Appender

Inherits:
Object
  • Object
show all
Defined in:
lib/logeasy/appender.rb

Overview

Appender super class. An instance of this class should not be created. It must be sub-classed. Sub-classes must provide a ‘write’ method that will output a message to the target device. A simple console logger and file logger are provided.

Direct Known Subclasses

ConsoleAppender, FileAppender

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#allow_unformatted_messagesObject

Returns the value of attribute allow_unformatted_messages.



19
20
21
# File 'lib/logeasy/appender.rb', line 19

def allow_unformatted_messages
  @allow_unformatted_messages
end

#formatterObject

Returns the value of attribute formatter.



16
17
18
# File 'lib/logeasy/appender.rb', line 16

def formatter
  @formatter
end

#loggerObject

Returns the value of attribute logger.



17
18
19
# File 'lib/logeasy/appender.rb', line 17

def logger
  @logger
end

#min_levelObject

Returns the value of attribute min_level.



18
19
20
# File 'lib/logeasy/appender.rb', line 18

def min_level
  @min_level
end

Instance Method Details

#do_log(log_item) ⇒ Object

Write this log item. If this appender’s level is higher than the log item’s level, this method will return immediately.

‘log_item’ - The log to write.



25
26
27
28
29
30
31
# File 'lib/logeasy/appender.rb', line 25

def do_log(log_item)
  return if log_item.level < min_level
  # Format the message and log it.
  # If the log item is marked as unformatted, then simple print, do not format.
  message = log_item.unformatted ? log_item.message : formatter.call(log_item)
  write(message)
end