Class: BBK::Utils::Logger

Inherits:
Logger
  • Object
show all
Defined in:
lib/bbk/utils/logger.rb

Constant Summary collapse

DEFAULT_NAME =
'bbk'
DEFAULT_LEVEL =
Logger::Severity::DEBUG

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(progname, level, io: STDOUT) ⇒ Logger

Returns a new instance of Logger.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bbk/utils/logger.rb', line 19

def initialize(progname, level, io: STDOUT)
  io.sync = true
  super(io)
  self.progname = progname

  if level.is_a?(Integer)
    self.level = level
  else
    level = level.to_s.upcase
    level = level.present? ? level : 'INFO'
    self.level = Logger.const_get(level)
  end

  self.formatter = LogFormatter.new
  info "Using LOG_LEVEL=#{level}"
end

Class Method Details

.defaultObject



40
41
42
43
44
45
46
47
# File 'lib/bbk/utils/logger.rb', line 40

def self.default
  unless @default
    level = ENV.fetch('LOG_LEVEL', DEFAULT_LEVEL)
    @default = new(DEFAULT_NAME, level)
    @default.level = level
  end
  @default
end

.new(*args, **kwargs) ⇒ Object



14
15
16
17
# File 'lib/bbk/utils/logger.rb', line 14

def self.new(*args, **kwargs)
  instance = super
  ActiveSupport::TaggedLogging.new(instance)
end

Instance Method Details

#silence(*_args) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



36
37
38
# File 'lib/bbk/utils/logger.rb', line 36

def silence(*_args)
  yield self
end