class Fluent::Log::ConsoleAdapter

Async gem which is used by http_server helper switched logger mechanism to Console gem which isn’t complatible with Ruby’s standard Logger (since v1.17). This class adapts it to Fluentd’s logger mechanism.

Public Class Methods

new(logger) click to toggle source
Calls superclass method
# File lib/fluent/log/console_adapter.rb, line 38
def initialize(logger)
  @logger = logger
  # When `verbose` is `true`, following items will be added as a prefix or
  # suffix of the subject:
  #   * Severity
  #   * Object ID
  #   * PID
  #   * Time
  # Severity and Time are added by Fluentd::Log too so they are redundant.
  # PID is the worker's PID so it's also redundant.
  # Object ID will be too verbose in usual cases.
  # So set it as `false` here to suppress redundant items.
  super(StringIO.new, verbose: false)
end
wrap(logger) click to toggle source
# File lib/fluent/log/console_adapter.rb, line 27
def self.wrap(logger)
  _, level = Console::Logger::LEVELS.find { |key, value|
    if logger.level <= 0
      key == :debug
    else
      value == logger.level - 1
    end
  }
  Console::Logger.new(ConsoleAdapter.new(logger), level: level)
end

Public Instance Methods

call(subject = nil, *arguments, name: nil, severity: 'info', **options, &block) click to toggle source
Calls superclass method
# File lib/fluent/log/console_adapter.rb, line 53
def call(subject = nil, *arguments, name: nil, severity: 'info', **options, &block)
  if LEVEL_TEXT.include?(severity.to_s)
    level = severity
  else
    @logger.warn("Unknown severity: #{severity}")
    level = 'warn'
  end

  @io.seek(0)
  @io.truncate(0)
  super
  @logger.send(level, @io.string.chomp)
end