Class: Lamian::Logger Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Provides thread-local loggers to catch teed messages from regular loggers. Uses :__lamian_logger thread variable

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Logger.



17
18
19
20
21
# File 'lib/lamian/logger.rb', line 17

def initialize
  super(nil)
  self.level = 0
  self.logdevs = []
end

Class Method Details

.currentLamian::Logger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Provides access to logger bound to curent thread

Returns:



13
14
15
# File 'lib/lamian/logger.rb', line 13

def self.current
  Thread.current[:__lamian_logger] ||= new
end

Instance Method Details

#add(*args, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Part of Logger api, entry point for all logs extened to run on each log device in stack



35
36
37
38
39
40
41
42
# File 'lib/lamian/logger.rb', line 35

def add(*args, &block)
  @formatter = Lamian.config.formatter

  logdevs.each do |logdev|
    @logdev = logdev
    super
  end
end

#dump(format: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Dumps log collected in this run

Parameters:

  • format (Hash) (defaults to: nil)

    a customizable set of options

Options Hash (format:):

  • requested (Symbol)

    format of log. At this point, returns raw log if falsey or log without controll sequences (such as ‘[23m’) if truthy value given (for now)

Returns:

  • formatted log (String by default)

See Also:



51
52
53
54
55
# File 'lib/lamian/logger.rb', line 51

def dump(format: nil)
  result = logdevs[-1]&.string&.dup
  apply_format!(format, result)
  result
end

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Collects logs sent inside block

See Also:



25
26
27
28
29
30
31
# File 'lib/lamian/logger.rb', line 25

def run
  logdevs.push(StringIO.new)

  yield
ensure
  logdevs.pop
end