Class: Hubbado::Log

Inherits:
Object
  • Object
show all
Includes:
Dependency
Defined in:
lib/hubbado/log.rb,
lib/hubbado/log/log.rb,
lib/hubbado/log/logger.rb,
lib/hubbado/log/log_handler.rb,
lib/hubbado/log/configuration.rb,
lib/hubbado/log/controls/data.rb,
lib/hubbado/log/controls/message.rb,
lib/hubbado/log/controls/subject.rb,
lib/hubbado/log/controls/exception.rb,
lib/hubbado/log/controls/log_handler.rb

Defined Under Namespace

Modules: Controls Classes: Configuration, LogHandler, Logger

Constant Summary collapse

SEVERITIES =

Ordered, because the level compares against them. trace is program flow, a line per iteration; debug is the completion of a secondary operation, or a detail worth keeping; info is the completion of the principal operation of a class or utility.

{ trace: 0, debug: 1, info: 2, warn: 3, error: 4, fatal: 5, unknown: 6 }.freeze
STACKTRACE_SEVERITIES =
%i[warn error fatal unknown].freeze
LEVEL_VARIABLE =
"LOG_LEVEL".freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject (readonly)

Returns the value of attribute config.



18
19
20
# File 'lib/hubbado/log/log.rb', line 18

def config
  @config
end

Class Method Details

.configuration {|@config| ... } ⇒ Object

Yields:



20
21
22
23
24
# File 'lib/hubbado/log/log.rb', line 20

def configuration
  yield @config

  @loggers = nil
end

.configure(receiver, attr_name: nil) ⇒ Object



59
60
61
62
63
64
# File 'lib/hubbado/log/log.rb', line 59

def self.configure(receiver, attr_name: nil)
  attr_name ||= :logger
  instance = Logger.new(receiver.class.name, loggers)
  receiver.public_send("#{attr_name}=", instance)
  instance
end

.inherited(cls) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/hubbado/log/log.rb', line 39

def self.inherited(cls)
  cls.class_exec do
    dependency_module = Module.new do
      define_singleton_method :included do |reciever_class|
        reciever_class.class_exec do
          ::Dependency::Attribute.define(self, :logger, cls)

          define_method :logger do
            @logger ||= cls.configure self
          end
        end
      end
    end

    const_set :Dependency, dependency_module
  end
end

.log(*args) ⇒ Object



34
35
36
# File 'lib/hubbado/log/log.rb', line 34

def log(*args)
  logger.log(*args)
end

.loggerObject



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

def logger
  @logger = Logger.new('', loggers)
end

.loggersObject



26
27
28
# File 'lib/hubbado/log/log.rb', line 26

def loggers
  @loggers ||= config.loggers.map(&:new)
end