class Patterns::Logger

Logger -> Object

The standard singleton pattern example - a logger to handle writing to a log file.

Attributes

output[R]

The output that will be written to a log file

Public Class Methods

new() click to toggle source

Initializes the Logger, the Singleton include will ensure it is only initialized once, and only when it needs to be called

  • log_file - The path of the log file

Examples

=> logger = Logger.instance
# File app/models/singleton/logger.rb, line 23
def initialize
  @output = ''
end

Public Instance Methods

error(message, log_file = DEFAULT_LOG_PATH) click to toggle source

Sets the format of our log message to error and writes data to the log file

  • message - The message to log

Examples

=> logger.error 'File not found'
# File app/models/singleton/logger.rb, line 34
def error(message, log_file = DEFAULT_LOG_PATH)
  @output = format(message, 'ERROR')
  write(log_file)
end
info(message, log_file = DEFAULT_LOG_PATH) click to toggle source

Sets the format of our log message to info and writes data to the log file

  • message - The message to log

Examples

=> logger.info 'This is some useful info'
# File app/models/singleton/logger.rb, line 46
def info(message, log_file = DEFAULT_LOG_PATH)
  @output = format(message, 'INFO')
  write(log_file)
end