Class: DevSuite::Utils::Logger::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dev_suite/utils/logger/base.rb

Constant Summary collapse

LOG_LEVELS =
[:none, :info, :warn, :error, :debug].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_level: :none) ⇒ Base

Returns a new instance of Base.



15
16
17
18
# File 'lib/dev_suite/utils/logger/base.rb', line 15

def initialize(log_level: :none)
  validate_log_level(log_level)
  @log_level = log_level
end

Instance Attribute Details

#log_levelObject

Returns the value of attribute log_level.



13
14
15
# File 'lib/dev_suite/utils/logger/base.rb', line 13

def log_level
  @log_level
end

Instance Method Details

#log(message, level: :none, emoji: nil, prefix: nil, color: nil) ⇒ Object

Logs a message with optional emoji, prefix, and color.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dev_suite/utils/logger/base.rb', line 21

def log(message, level: :none, emoji: nil, prefix: nil, color: nil)
  validate_log_level(level)
  return if skip_logging?(level)

  options = {
    level: level,
    emoji: emoji,
    prefix: prefix,
    color: color,
  }

  formatted_message = Formatter.format(message, options)
  output_log(formatted_message)
end