Class: Clogs::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/clogs/log.rb

Overview

Lacci insists on a logging implementation being plugged in before any Shoes object exists. Scarpe ships two (one backed by the logging gem, one simple); Clogs has its own so that a packaged app needs no logging dependency at all.

Configure with SCARPE_LOG_LEVEL (debug/info/warn/error/fatal) or SCARPE_DEBUG=1.

Defined Under Namespace

Classes: Logger

Constant Summary collapse

LEVELS =
{ debug: 0, info: 1, warn: 2, error: 3, fatal: 4 }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(out = $stderr) ⇒ Log

Returns a new instance of Log.



14
15
16
17
# File 'lib/clogs/log.rb', line 14

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

Instance Method Details

#configure_logger(config) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/clogs/log.rb', line 19

def configure_logger(config)
  level = if ENV["SCARPE_LOG_LEVEL"]
    ENV["SCARPE_LOG_LEVEL"].downcase.to_sym
  elsif config.is_a?(Hash)
    (config["default"] || config[:default] || "warn").to_s.to_sym
  else
    :warn
  end
  @level = LEVELS.key?(level) ? level : :warn
end

#emit(component, level, message) ⇒ Object



34
35
36
37
38
# File 'lib/clogs/log.rb', line 34

def emit(component, level, message)
  return if LEVELS[level] < LEVELS[@level]

  @out.puts("[#{level.to_s.upcase}] #{component}: #{message}")
end

#logger_for_component(component) ⇒ Object



30
31
32
# File 'lib/clogs/log.rb', line 30

def logger_for_component(component)
  Logger.new(self, component.to_s)
end