Module: Fluent::PluginLoggerMixin

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#logObject

Returns the value of attribute log.



494
495
496
# File 'lib/fluent/log.rb', line 494

def log
  @log
end

Class Method Details

.included(klass) ⇒ Object



481
482
483
484
485
486
# File 'lib/fluent/log.rb', line 481

def self.included(klass)
  klass.instance_eval {
    desc 'Allows the user to set different levels of logging for each plugin.'
    config_param :@log_level, :string, default: nil, alias: :log_level # 'log_level' will be warned as deprecated
  }
end

Instance Method Details

#configure(conf) ⇒ Object



496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
# File 'lib/fluent/log.rb', line 496

def configure(conf)
  super

  if plugin_id_configured? || conf['@log_level']
    @log = PluginLogger.new($log.dup) unless @log.is_a?(PluginLogger)
    @log.optional_attrs = {}

    if level = conf['@log_level']
      @log.level = level
    end

    if plugin_id_configured?
      @log.optional_header = "[#{@id}] "
    end
  end
end

#initializeObject



488
489
490
491
492
# File 'lib/fluent/log.rb', line 488

def initialize
  super

  @log = $log # Use $log object directly by default
end

#terminateObject



513
514
515
516
# File 'lib/fluent/log.rb', line 513

def terminate
  super
  @log.reset
end