All Projects → fluent → Fluent Logger Ruby

fluent / Fluent Logger Ruby

Licence: other
A structured logger for Fluentd (Ruby)

Programming Languages

ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Fluent Logger Ruby

Log Pilot
Collect logs for docker containers
Stars: ✭ 1,112 (+367.23%)
Mutual labels:  fluentd
Aws Eks Kubernetes Masterclass
AWS EKS Kubernetes - Masterclass | DevOps, Microservices
Stars: ✭ 129 (-45.8%)
Mutual labels:  fluentd
Fluent Plugin Mongo
MongoDB input and output plugin for Fluentd
Stars: ✭ 163 (-31.51%)
Mutual labels:  fluentd
Fluent Plugin Sql
SQL input/output plugin for Fluentd
Stars: ✭ 82 (-65.55%)
Mutual labels:  fluentd
Fluentd
Fluentd: Unified Logging Layer (project under CNCF)
Stars: ✭ 10,807 (+4440.76%)
Mutual labels:  fluentd
Pathivu
An efficient log ingestion and log aggregation system https://pathivu.io/
Stars: ✭ 146 (-38.66%)
Mutual labels:  fluentd
Fluent Plugin Zabbix
fluentd out plugin to zabbix
Stars: ✭ 46 (-80.67%)
Mutual labels:  fluentd
Fluent Logger Java
A structured logger for Fluentd (Java)
Stars: ✭ 186 (-21.85%)
Mutual labels:  fluentd
Fluent Plugin Systemd
This is a fluentd input plugin. It reads logs from the systemd journal.
Stars: ✭ 124 (-47.9%)
Mutual labels:  fluentd
Fluentular
Fluentular is a Fluentd regular expression editor
Stars: ✭ 154 (-35.29%)
Mutual labels:  fluentd
Go Fluentd
rewrite fluentd in golang
Stars: ✭ 89 (-62.61%)
Mutual labels:  fluentd
Fluent Agent Hydra
A Fluentd log agent.
Stars: ✭ 102 (-57.14%)
Mutual labels:  fluentd
Dagger
Dagger 是一个基于 Loki 的日志查询和管理系统,它是由达闼科技( CloudMinds )云团队的`大禹基础设施平台`派生出来的一个项目。Dagger 运行在 Loki 前端,具备日志查询、搜索,保存和下载等特性,适用于云原生场景下的容器日志管理场景。
Stars: ✭ 149 (-37.39%)
Mutual labels:  fluentd
Fluent Plugin Concat
Fluentd Filter plugin to concatenate multiline log separated in multiple events.
Stars: ✭ 78 (-67.23%)
Mutual labels:  fluentd
Gofluent
(Not Maintained) Something acting like fluentd rewritten in Go.
Stars: ✭ 174 (-26.89%)
Mutual labels:  fluentd
Fluent Plugin Splunk Hec
This is the Fluentd output plugin for sending events to Splunk via HEC.
Stars: ✭ 56 (-76.47%)
Mutual labels:  fluentd
Terraform Aws Elasticsearch
Terraform module to provision an Elasticsearch cluster with built-in integrations with Kibana and Logstash.
Stars: ✭ 137 (-42.44%)
Mutual labels:  fluentd
Fluent Logger Node
A structured logger for Fluentd (Node.js)
Stars: ✭ 233 (-2.1%)
Mutual labels:  fluentd
Fluent Plugin Cloudwatch Logs
CloudWatch Logs Plugin for Fluentd
Stars: ✭ 179 (-24.79%)
Mutual labels:  fluentd
Fluent Plugin Rewrite Tag Filter
Fluentd Output filter plugin to rewrite tags that matches specified attribute.
Stars: ✭ 151 (-36.55%)
Mutual labels:  fluentd

Fluent logger

Build Status

A structured event logger

Installation

Add this line to your application's Gemfile:

gem 'fluent-logger'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install fluent-logger

Examples

Simple

require 'fluent-logger'

# API: FluentLogger.new(tag_prefix, options)
log = Fluent::Logger::FluentLogger.new(nil, :host => 'localhost', :port => 24224)
unless log.post("myapp.access", {"agent" => "foo"})
  p log.last_error # You can get last error object via last_error method
end

# output: myapp.access {"agent":"foo"}

UNIX socket

require 'fluent-logger'

log = Fluent::Logger::FluentLogger.new(nil, :socket_path => "/tmp/fluent.sock")
unless log.post("myapp.access", {"agent" => "foo"})
  # Passed records are stored into logger's internal buffer so don't re-post same event.
  p log.last_error # You can get last error object via last_error method
end

# output: myapp.access {"agent":"foo"}

Tag prefix

require 'fluent-logger'

log = Fluent::Logger::FluentLogger.new('myapp', :host => 'localhost', :port => 24224)
log.post("access", {"agent" => "foo"})

# output: myapp.access {"agent":"foo"}

Nonblocking write

require 'fluent-logger'

log = Fluent::Logger::FluentLogger.new(nil, :host => 'localhost', :port => 24224, :use_nonblock => true, :wait_writeable => false)
# When wait_writeable is false
begin
  log.post("myapp.access", {"agent" => "foo"})
rescue IO::EAGAINWaitWritable => e
  # wait code for avoding "Resource temporarily unavailable"
  # Passed records are stored into logger's internal buffer so don't re-post same event.
end

# When wait_writeable is true
unless log.post("myapp.access", {"agent" => "foo"})
  # same as other example
end

# output: myapp.access {"agent":"foo"}

TLS setting

require 'fluent-logger'

tls_opts = {
  :ca   => '/path/to/cacert.pem',
  :cert => '/path/to/client-cert.pem',
  :key  => '/path/to/client-key.pem',
  :key_passphrase => 'test'
}
log = Fluent::Logger::FluentLogger.new(nil, :host => 'localhost', :port => 24224, :tls_options => tls_opts)

in_forward config example:

<source>
  @type forward
  <transport tls>
    version TLS1_2
    ca_path /path/to/cacert.pem
    cert_path /path/to/server-cert.pem
    private_key_path /path/to/server-key.pem
    private_key_passphrase test
    client_cert_auth true
  </transport>
</source>

Singleton

require 'fluent-logger'

Fluent::Logger::FluentLogger.open(nil, :host => 'localhost', :port => 24224)
Fluent::Logger.post("myapp.access", {"agent" => "foo"})

# output: myapp.access {"agent":"foo"}

Logger options

host (String)

fluentd instance host

port (Integer)

fluentd instance port

socket_path (String)

If specified, fluentd uses unix domain socket instead of TCP.

nanosecond_precision (Bool)

Use nano second event time instead of epoch. See also "Tips" section.

use_nonblock (Bool)

Use nonblocking write(IO#write_nonblock) instead of normal write(IO#write). If Logger#post stuck on your environment, specify true. Default: false

wait_writeable (Bool)

If false, Logger#post raises an error when nonblocking write gets EAGAIN (i.e. use_nonblock must be true, otherwise this will have no effect). Default: true

buffer_overflow_handler (Proc)

Pass callback for handling buffer overflow with pending data. See "Buffer overflow" section.

tls_options (Hash)

Pass TLS related options.

  • use_default_ca: Set true if you want to use default CA
  • ca: CA file path
  • cert: Certificate file path
  • key: Private key file path
  • key_passphrase: Private key passphrase
  • version: TLS version. Default is OpenSSL::SSL::TLS1_2_VERSION
  • ciphers: The list of cipher suites. Default is ALL:!aNULL:!eNULL:!SSLv2
  • insecure: Set true when in_forward uses insecure true

Standard ::Logger compatible interface

Example1

require 'fluent-logger'
f = Fluent::Logger::LevelFluentLogger.new('fluent')

f.info("some application running.")
# output: fluent.info: {"level":"INFO","message":"some application running."}

f.warn("some application running.")
# output: fluent.warn: {"level":"WARN","message":"some application running."}

Example2(add progname)

require 'fluent-logger'
f = Fluent::Logger::LevelFluentLogger.new('fluent')
f.info("some_application") {"some application running."}
# output: fluent.info: {"level":"INFO","message":"some application running.","progname":"some_application"}

Example3(set log level)

require 'fluent-logger'
f = Fluent::Logger::LevelFluentLogger.new('fluent')
f.level = Logger::WARN
f.info("some_application") {"some application running."}

Log level is ERROR so no output.

default log level is debug.

Example4(customize format for Rails)

require 'fluent-logger'
f = Fluent::Logger::LevelFluentLogger.new('fluent')

f.formatter = proc do |severity, datetime, progname, message|
  map = { level: severity }
  map[:message] = message if message
  map[:progname] = progname if progname
  map[:stage] = ENV['RAILS_ENV']
  map[:service_name] = "SomeApp"
  map
end

f.info("some_application"){"some application running."}
# output: fluent.info: {"level":"INFO","message":"some application running.","progname":"some_application","stage":"production","service_name":"SomeApp"}

Loggers

Fluent

Fluent::Logger::FluentLogger.open('tag_prefix', :host => 'localhost', :port => 24224)

Console

Fluent::Logger::ConsoleLogger.open(io)

Null

Fluent::Logger::NullLogger.open

Tips

Use nanosecond-precision time

To send events with nanosecond-precision time (Fluent 0.14 and up), specify nanosecond_precision to FluentLogger constructor.

log = Fluent::Logger::FluentLogger.new(nil, :host => 'localhost', :port => 24224, :nanosecond_precision => true)
# Use nanosecond time instead
log.post("myapp.access", {"agent" => "foo"})
log.post_with_time("myapp.access", {"agent" => "foo"}, Time.now) # Need Time object for post_with_time

Buffer overflow

You can inject your own custom proc to handle buffer overflow in the event of connection failure. This will mitigate the loss of data instead of simply throwing data away.

Your proc must accept a single argument, which will be the internal buffer of messages from the logger. A typical use-case for this would be writing to disk or possibly writing to Redis.

Example
class BufferOverflowHandler
  attr_accessor :buffer

  def flush(messages)
    @buffer ||= []
    MessagePack::Unpacker.new.feed_each(messages) do |msg|
      @buffer << msg
    end
  end
end

handler = Proc.new { |messages| BufferOverflowHandler.new.flush(messages) }

Fluent::Logger::FluentLogger.new(nil,
  :host => 'localhost', :port => 24224,
  :buffer_overflow_handler => handler)

Information

name description
Web site http://fluentd.org/
Documents http://docs.fluentd.org/
Source repository https://github.com/fluent/fluent-logger-ruby
Author Sadayuki Furuhashi
Copyright (c) 2011 FURUHASHI Sadayuki
License Apache License, Version 2.0
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].