Class: Rack::Access::Capture::Collector::FluentdAdapter

Inherits:
AbstractAdapter show all
Defined in:
lib/rack/access/capture/collector/fluentd_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FluentdAdapter

Returns a new instance of FluentdAdapter.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rack/access/capture/collector/fluentd_adapter.rb', line 13

def initialize(options = {})
  config = options || {}
  @tag = config["tag"] || 'development'
  tag_prefix = config["tag_prefix"]
  host = config["host"] || 'localhost'
  port = config["port"] || 24224
  handler = proc { |messages| BufferOverflowHandler.new(config["log_file_path"]).flush(messages) }
  buffer_limit = config["buffer_limit"] || 131072 # Buffer limit of the standard is 128.kilobyte
  log_reconnect_error_threshold = config["log_reconnect_error_threshold"] || Fluent::Logger::FluentLogger::RECONNECT_WAIT_MAX_COUNT
  options = { host: host,
              port: port,
              buffer_limit: buffer_limit,
              buffer_overflow_handler: handler,
              log_reconnect_error_threshold: log_reconnect_error_threshold }
  @logger = config["logger"] || Fluent::Logger::FluentLogger.new(tag_prefix, options)
  exclude_request = config["exclude_request"] || []
  @collect = [GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, LINK, UNLINK, TRACE] - exclude_request
end

Instance Attribute Details

#tagObject (readonly)

Returns the value of attribute tag.



11
12
13
# File 'lib/rack/access/capture/collector/fluentd_adapter.rb', line 11

def tag
  @tag
end

Instance Method Details

#collect(log) ⇒ Object



36
37
38
# File 'lib/rack/access/capture/collector/fluentd_adapter.rb', line 36

def collect(log)
  @logger.post(@tag, log)
end

#collect?(env) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/rack/access/capture/collector/fluentd_adapter.rb', line 32

def collect?(env)
  @collect.include?(env["REQUEST_METHOD"])
end