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.



654
655
656
# File 'lib/fluent/log.rb', line 654

def log
  @log
end

Class Method Details

.included(klass) ⇒ Object



641
642
643
644
645
646
# File 'lib/fluent/log.rb', line 641

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



656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
# File 'lib/fluent/log.rb', line 656

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



648
649
650
651
652
# File 'lib/fluent/log.rb', line 648

def initialize
  super

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

#terminateObject



673
674
675
676
# File 'lib/fluent/log.rb', line 673

def terminate
  super
  @log.reset
end