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 =
{ debug: 0, info: 1, warn: 2, error: 3, fatal: 4, unknown: 5 }.freeze
STACKTRACE_SEVERITIES =
%i[warn error fatal unknown].freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/hubbado/log/log.rb', line 11

def config
  @config
end

Class Method Details

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

Yields:



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

def configuration
  yield @config

  @loggers = nil
end

.configure(receiver, attr_name: nil) ⇒ Object



52
53
54
55
56
57
# File 'lib/hubbado/log/log.rb', line 52

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



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/hubbado/log/log.rb', line 32

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



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

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

.loggerObject



23
24
25
# File 'lib/hubbado/log/log.rb', line 23

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

.loggersObject



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

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