Module: SteamCondenser::Logging

Overview

This module is included by all classes of Steam Condenser that log events

It is a lightweight wrapper around Ruby's Logger class from the standard library.

Constant Summary collapse

@@formatter =
::Logger::Formatter.new
@@level =
::Logger::Severity::WARN
@@logdev =
STDOUT

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.formatter=(formatter) ⇒ Object

Sets the default formatter to use for all logging events in Steam Condenser


46
47
48
# File 'lib/steam-condenser/logging.rb', line 46

def self.formatter=(formatter)
  @@formatter = formatter
end

.included(klass) ⇒ Object

Creates a logger for the class that includes this module

Additionally it defines a .log singleton method for the class that includes this module


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/steam-condenser/logging.rb', line 26

def self.included(klass)
  klass.send :class_variable_set, :@@logger, nil
  klass.define_singleton_method :log do
    logger = class_variable_get :@@logger
    if logger.nil?
      logger = ::Logger.new @@logdev
      logger.formatter = @@formatter
      logger.level = @@level
      logger.progname = klass.name

      class_variable_set :@@logger, logger
    end
    logger
  end
end

.level=(level) ⇒ Object

Sets the default log level to use for filtering all logging events in Steam Condenser


62
63
64
# File 'lib/steam-condenser/logging.rb', line 62

def self.level=(level)
  @@level = level
end

.logdev=(logdev) ⇒ Object

Sets the default logging device to use for all logging events in Steam Condenser


54
55
56
# File 'lib/steam-condenser/logging.rb', line 54

def self.logdev=(logdev)
  @@logdev = logdev
end

Instance Method Details

#logLogger

Returns the logger for the current class


69
70
71
# File 'lib/steam-condenser/logging.rb', line 69

def log
  self.class.log
end