Class: Hubbado::Log

Inherits:
Object
  • Object
show all
Includes:
Dependency
Defined in:
lib/hubbado/log.rb,
lib/hubbado/log/log.rb,
lib/hubbado/log/tags.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/logger.rb,
lib/hubbado/log/controls/message.rb,
lib/hubbado/log/controls/subject.rb,
lib/hubbado/log/logger/substitute.rb,
lib/hubbado/log/controls/exception.rb,
lib/hubbado/log/controls/log_handler.rb

Defined Under Namespace

Modules: Controls Classes: Configuration, LogHandler, Logger, Tags

Constant Summary collapse

SEVERITIES =

Ordered, because the level compares against them. trace is program flow, a message 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
TAGS_VARIABLE =
"LOG_TAGS".freeze

Class Method Summary collapse

Class Method Details

.configObject

Held by the configuration itself rather than here, because a class-level instance variable is not inherited: a subclass asking this class would answer nil.



17
# File 'lib/hubbado/log/log.rb', line 17

def config = Configuration.instance

.configuration(&block) ⇒ Object



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

def configuration(&block)
  config.change(&block)
end

.configure(receiver, attr_name: nil) ⇒ Object



57
58
59
60
61
62
# File 'lib/hubbado/log/log.rb', line 57

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



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

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, tag: nil, tags: nil) ⇒ Object

The keywords are named rather than swept up with the positionals: a method taking only *args accepts no keywords, so Ruby would fold them into a trailing hash and they would arrive as the message's data — which a handler hands to Rollbar as the exception.



32
33
34
# File 'lib/hubbado/log/log.rb', line 32

def log(*args, tag: nil, tags: nil)
  logger.log(*args, tag: tag, tags: tags)
end

.loggerObject



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

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

.loggersObject



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

def loggers = config.log_handlers