Class: Roast::Helpers::Logger

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/roast/helpers/logger.rb

Overview

Central logger for the Roast application

Constant Summary collapse

VALID_LOG_LEVELS =
["DEBUG", "INFO", "WARN", "ERROR", "FATAL"].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout: $stdout, log_level: ENV["ROAST_LOG_LEVEL"] || "INFO") ⇒ Logger

Returns a new instance of Logger.



33
34
35
36
# File 'lib/roast/helpers/logger.rb', line 33

def initialize(stdout: $stdout, log_level: ENV["ROAST_LOG_LEVEL"] || "INFO")
  @log_level = validate_log_level(log_level)
  @logger = create_logger(stdout)
end

Instance Attribute Details

#log_levelObject

Returns the value of attribute log_level.



13
14
15
# File 'lib/roast/helpers/logger.rb', line 13

def log_level
  @log_level
end

#loggerObject (readonly)

Returns the value of attribute logger.



13
14
15
# File 'lib/roast/helpers/logger.rb', line 13

def logger
  @logger
end

Class Method Details

.instanceObject



46
47
48
# File 'lib/roast/helpers/logger.rb', line 46

def instance
  @instance ||= new
end

.resetObject

For testing purposes



54
55
56
# File 'lib/roast/helpers/logger.rb', line 54

def reset
  @instance = nil
end

Instance Method Details

#debug(message) ⇒ Object

Create a specialized debug method that ensures proper functionality



19
20
21
# File 'lib/roast/helpers/logger.rb', line 19

def debug(message)
  logger.debug(message)
end

#error(message) ⇒ Object



23
24
25
26
# File 'lib/roast/helpers/logger.rb', line 23

def error(message)
  # Add any custom error handling logic here
  logger.error(message)
end

#fatal(message) ⇒ Object



28
29
30
31
# File 'lib/roast/helpers/logger.rb', line 28

def fatal(message)
  # Add any custom fatal error handling logic here
  logger.fatal(message)
end