Parent

Fluent::Logger::FluentLogger

Attributes

last_error[R]
limit[RW]
log_reconnect_error_threshold[RW]
logger[RW]

Public Class Methods

new(tag_prefix = '', *args) click to toggle source
# File lib/fluent/logger/fluent_logger.rb, line 39
def initialize(tag_prefix = '', *args)
  super()

  options = {
    :host => 'localhost',
    :port => 24224
  }

  case args.first
  when String, Symbol
    # backward compatible
    options[:host] = args[0]
    options[:port] = args[1] if args[1]
  when Hash
    options.update args.first
  end

  @tag_prefix = tag_prefix
  @host = options[:host]
  @port = options[:port]

  @mon = Monitor.new
  @pending = nil
  @connect_error_history = []

  @limit = options[:buffer_limit] || BUFFER_LIMIT
  @log_reconnect_error_threshold = options[:log_reconnect_error_threshold] ||  RECONNECT_WAIT_MAX_COUNT

  if logger = options[:logger]
    @logger = logger
  else
    @logger = ::Logger.new(STDERR)
    if options[:debug]
      @logger.level = ::Logger::DEBUG
    else
      @logger.level = ::Logger::INFO
    end
  end

  @last_error = {}

  begin
    connect!
  rescue => e
    set_last_error(e)
    @logger.error "Failed to connect fluentd: #{$!}"
    @logger.error "Connection will be retried."
  end

  at_exit { close }
end

Public Instance Methods

close() click to toggle source
# File lib/fluent/logger/fluent_logger.rb, line 104
def close
  @mon.synchronize {
    if @pending
      begin
        send_data(@pending)
      rescue => e
        set_last_error(e)
        @logger.error("FluentLogger: Can't send logs to #{@host}:#{@port}: #{$!}")
      end
    end
    @con.close if connect?
    @con = nil
    @pending = nil
  }
  self
end
connect?() click to toggle source
# File lib/fluent/logger/fluent_logger.rb, line 121
def connect?
  !!@con
end
post_with_time(tag, map, time) click to toggle source
# File lib/fluent/logger/fluent_logger.rb, line 98
def post_with_time(tag, map, time)
  @logger.debug { "event: #{tag} #{map.to_json}" rescue nil } if @logger.debug?
  tag = "#{@tag_prefix}.#{tag}" if @tag_prefix
  write [tag, time.to_i, map]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.