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.



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

def log
  @log
end

Class Method Details

.included(klass) ⇒ Object



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

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



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

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



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

def initialize
  super

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

#terminateObject



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

def terminate
  super
  @log.reset
end