Class: Cogger::Hub

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/cogger/hub.rb

Overview

Loads configuration and simultaneously sends messages to multiple streams. :reek:TooManyMethods

Instance Method Summary collapse

Constructor Details

#initialize(registry: Cogger, model: Configuration, **attributes) ⇒ Hub

Returns a new instance of Hub.



37
38
39
40
41
42
# File 'lib/cogger/hub.rb', line 37

def initialize(registry: Cogger, model: Configuration, **attributes)
  @registry = registry
  @configuration = model[**find_formatter(attributes)]
  @primary = configuration.to_logger
  @streams = [@primary]
end

Instance Method Details

#abort(message = nil, **payload, &block) ⇒ Object



62
63
64
65
# File 'lib/cogger/hub.rb', line 62

def abort(message = nil, **payload, &block)
  error(message, **payload, &block) if message || !payload.empty? || block
  exit false
end

#add(level, message = nil) ⇒ Object



72
73
74
# File 'lib/cogger/hub.rb', line 72

def add(level, message = nil, **, &)
  log(Logger::SEV_LABEL.fetch(level, "ANY").downcase, message, **, &)
end

#add_stream(**attributes) ⇒ Object



44
45
46
47
48
# File 'lib/cogger/hub.rb', line 44

def add_stream **attributes
  attributes[:id] = configuration.id
  streams.append configuration.with(**find_formatter(attributes)).to_logger
  self
end

#any(message = nil) ⇒ Object Also known as: unknown



60
# File 'lib/cogger/hub.rb', line 60

def any(message = nil, **, &) = log(__method__, message, **, &)

#debug(message = nil) ⇒ Object



50
# File 'lib/cogger/hub.rb', line 50

def debug(message = nil, **, &) = log(__method__, message, **, &)

#error(message = nil) ⇒ Object



56
# File 'lib/cogger/hub.rb', line 56

def error(message = nil, **, &) = log(__method__, message, **, &)

#fatal(message = nil) ⇒ Object



58
# File 'lib/cogger/hub.rb', line 58

def fatal(message = nil, **, &) = log(__method__, message, **, &)

#info(message = nil) ⇒ Object



52
# File 'lib/cogger/hub.rb', line 52

def info(message = nil, **, &) = log(__method__, message, **, &)

#inspectObject



80
81
82
# File 'lib/cogger/hub.rb', line 80

def inspect
  %(#<#{self.class} #{configuration.inspect.delete_prefix! "#<Cogger::Configuration "})
end

#panic(message = nil, **payload, &block) ⇒ Object



67
68
69
70
# File 'lib/cogger/hub.rb', line 67

def panic(message = nil, **payload, &block)
  fatal(message, **payload, &block) if message || !payload.empty? || block
  exit false
end

#rereadObject



78
# File 'lib/cogger/hub.rb', line 78

def reread = primary.reread

#warn(message = nil) ⇒ Object



54
# File 'lib/cogger/hub.rb', line 54

def warn(message = nil, **, &) = log(__method__, message, **, &)