Class: Fluent::PluginLogger

Inherits:
Log
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/fluent/log.rb

Overview

PluginLogger has own log level separated from global $log object. This class enables log_level option in each plugin.

PluginLogger has same functionality as Log but some methods are forwarded to internal logger for keeping logging action consistency in the process, e.g. color, event, etc.

Direct Known Subclasses

Test::TestLogger

Constant Summary

Constants inherited from Log

Log::LEVEL_DEBUG, Log::LEVEL_ERROR, Log::LEVEL_FATAL, Log::LEVEL_INFO, Log::LEVEL_TEXT, Log::LEVEL_TRACE, Log::LEVEL_WARN, Log::LOG_EVENT_LABEL, Log::LOG_EVENT_TAG_PREFIX, Log::LOG_ROTATE_AGE, Log::LOG_TYPES, Log::LOG_TYPE_DEFAULT, Log::LOG_TYPE_SUPERVISOR, Log::LOG_TYPE_WORKER0

Instance Attribute Summary

Attributes inherited from Log

#format, #ignore_repeated_log_interval, #ignore_same_log_interval, #level, #log_event_enabled, #optional_attrs, #optional_header, #out, #time_format

Instance Method Summary collapse

Methods inherited from Log

#caller_line, #debug, #debug_backtrace, #disable_events, #dump_stacktrace, #dup, #enable_color?, #enable_debug, #enable_event, #error, #error_backtrace, #event, event_tags, #fatal, #fatal_backtrace, #flush, #format_time, #get_worker_id, #ignore_repeated_log?, #ignore_same_log?, #info, #info_backtrace, #log_type, #logdev=, #on_debug, #on_error, #on_fatal, #on_info, #on_trace, #on_warn, #puts, #reopen!, #reset, #skipped_type?, str_to_level, #suppress_stacktrace?, #trace, #trace_backtrace, #warn, #warn_backtrace, #write

Constructor Details

#initialize(logger) ⇒ PluginLogger

Returns a new instance of PluginLogger.



589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'lib/fluent/log.rb', line 589

def initialize(logger)
  @logger = logger
  @level = @logger.level
  @format = nil
  @depth_offset = 2
  if logger.instance_variable_defined?(:@suppress_repeated_stacktrace)
    @suppress_repeated_stacktrace = logger.instance_variable_get(:@suppress_repeated_stacktrace)
  end
  if logger.instance_variable_defined?(:@ignore_repeated_log_interval)
    @ignore_repeated_log_interval = logger.instance_variable_get(:@ignore_repeated_log_interval)
  end
  if logger.instance_variable_defined?(:@ignore_same_log_interval)
    @ignore_same_log_interval = logger.instance_variable_get(:@ignore_same_log_interval)
  end

  self.format = @logger.format
  self.time_format = @logger.time_format
  enable_color @logger.enable_color?
end

Instance Method Details

#enable_color(b = true) ⇒ Object



627
628
629
630
# File 'lib/fluent/log.rb', line 627

def enable_color(b = true)
  orig_enable_color b
  @logger.enable_color b
end

#format=(fmt) ⇒ Object



617
618
619
620
# File 'lib/fluent/log.rb', line 617

def format=(fmt)
  self.orig_format = fmt
  @logger.format = fmt
end

#level=(log_level_str) ⇒ Object



609
610
611
# File 'lib/fluent/log.rb', line 609

def level=(log_level_str)
  @level = Log.str_to_level(log_level_str)
end

#orig_enable_colorObject



615
# File 'lib/fluent/log.rb', line 615

alias orig_enable_color enable_color

#orig_format=Object



613
# File 'lib/fluent/log.rb', line 613

alias orig_format= format=

#orig_time_format=Object



614
# File 'lib/fluent/log.rb', line 614

alias orig_time_format= time_format=

#time_format=(fmt) ⇒ Object



622
623
624
625
# File 'lib/fluent/log.rb', line 622

def time_format=(fmt)
  self.orig_time_format = fmt
  @logger.time_format = fmt
end