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.



693
694
695
# File 'lib/fluent/log.rb', line 693

def log
  @log
end

Class Method Details

.included(klass) ⇒ Object



680
681
682
683
684
685
# File 'lib/fluent/log.rb', line 680

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



695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
# File 'lib/fluent/log.rb', line 695

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



687
688
689
690
691
# File 'lib/fluent/log.rb', line 687

def initialize
  super

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

#terminateObject



712
713
714
715
# File 'lib/fluent/log.rb', line 712

def terminate
  super
  @log.reset
end