Class: Fluent::Log::ConsoleAdapter
- Inherits:
-
Object
- Object
- Fluent::Log::ConsoleAdapter
- Defined in:
- lib/fluent/log/console_adapter.rb
Overview
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.
Class Method Summary collapse
Instance Method Summary collapse
- #call(subject = nil, *arguments, name: nil, severity: 'info', **options, &block) ⇒ Object
-
#initialize(logger) ⇒ ConsoleAdapter
constructor
A new instance of ConsoleAdapter.
Constructor Details
#initialize(logger) ⇒ ConsoleAdapter
Returns a new instance of ConsoleAdapter.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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 |
Class Method Details
.wrap(logger) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# 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 |
Instance Method Details
#call(subject = nil, *arguments, name: nil, severity: 'info', **options, &block) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fluent/log/console_adapter.rb', line 53 def call(subject = nil, *arguments, name: nil, severity: 'info', **, &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 |