Class: QuietQuality::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/quiet_quality/logger.rb

Constant Summary collapse

LEVEL_UPS =
{none: :warn, warn: :info, info: :debug}.freeze
LEVELS =
{none: 0, warn: 1, info: 2, debug: 3}.freeze
COLORS =
{warn: :yellow, info: :light_blue, debug: :light_cyan}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level: :warn, stream: $stderr) ⇒ Logger

Returns a new instance of Logger.



7
8
9
10
# File 'lib/quiet_quality/logger.rb', line 7

def initialize(level: :warn, stream: $stderr)
  @level = level
  @stream = stream
end

Instance Attribute Details

#levelObject

Returns the value of attribute level.



12
13
14
# File 'lib/quiet_quality/logger.rb', line 12

def level
  @level
end

Instance Method Details

#debug(message, data: nil) ⇒ Object



36
37
38
# File 'lib/quiet_quality/logger.rb', line 36

def debug(message, data: nil)
  log_message(message, data, :debug)
end

#increase_level!Object



14
15
16
17
# File 'lib/quiet_quality/logger.rb', line 14

def increase_level!
  next_level = LEVEL_UPS.fetch(level, nil)
  self.level = next_level if next_level
end

#info(message, data: nil) ⇒ Object



32
33
34
# File 'lib/quiet_quality/logger.rb', line 32

def info(message, data: nil)
  log_message(message, data, :info)
end

#show?(message_level) ⇒ Boolean

Returns:

  • (Boolean)


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

def show?(message_level)
  LEVELS[message_level] <= LEVELS[level]
end

#warn(message, data: nil) ⇒ Object



28
29
30
# File 'lib/quiet_quality/logger.rb', line 28

def warn(message, data: nil)
  log_message(message, data, :warn)
end