{"id":13498419,"url":"https://github.com/fluent/fluent-logger-ruby","last_synced_at":"2025-05-14T08:06:31.887Z","repository":{"id":1599667,"uuid":"2154022","full_name":"fluent/fluent-logger-ruby","owner":"fluent","description":"A structured logger for Fluentd (Ruby)","archived":false,"fork":false,"pushed_at":"2025-02-15T11:41:32.000Z","size":227,"stargazers_count":254,"open_issues_count":11,"forks_count":77,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-04-13T00:39:10.524Z","etag":null,"topics":["fluentd","fluentd-logger","ruby"],"latest_commit_sha":null,"homepage":"http://fluentd.org/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fluent.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog","contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-08-04T11:03:10.000Z","updated_at":"2025-03-09T14:21:34.000Z","dependencies_parsed_at":"2025-03-01T06:11:30.746Z","dependency_job_id":"a030a75c-d9c9-4d5a-b94f-01c401bb2669","html_url":"https://github.com/fluent/fluent-logger-ruby","commit_stats":{"total_commits":204,"total_committers":35,"mean_commits":5.828571428571428,"dds":0.6813725490196079,"last_synced_commit":"fd471f9715f77c0a77492c48446e858913a03602"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluent%2Ffluent-logger-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluent%2Ffluent-logger-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluent%2Ffluent-logger-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluent%2Ffluent-logger-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fluent","download_url":"https://codeload.github.com/fluent/fluent-logger-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254101616,"owners_count":22014909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fluentd","fluentd-logger","ruby"],"created_at":"2024-07-31T21:00:27.967Z","updated_at":"2025-05-14T08:06:26.872Z","avatar_url":"https://github.com/fluent.png","language":"Ruby","readme":"# Fluent logger\n\n[![Build Status](https://github.com/fluent/fluent-logger-ruby/actions/workflows/linux.yml/badge.svg?branch=master)](https://github.com/fluent/fluent-logger-ruby/actions/workflows/linux.yml)\n\nA structured event logger\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'fluent-logger'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install fluent-logger\n\n## Examples\n\n### Simple\n\n```ruby\nrequire 'fluent-logger'\n\n# API: FluentLogger.new(tag_prefix, options)\nlog = Fluent::Logger::FluentLogger.new(nil, :host =\u003e 'localhost', :port =\u003e 24224)\nunless log.post(\"myapp.access\", {\"agent\" =\u003e \"foo\"})\n  p log.last_error # You can get last error object via last_error method\nend\n\n# output: myapp.access {\"agent\":\"foo\"}\n```\n\n### UNIX socket\n\n```ruby\nrequire 'fluent-logger'\n\nlog = Fluent::Logger::FluentLogger.new(nil, :socket_path =\u003e \"/tmp/fluent.sock\")\nunless log.post(\"myapp.access\", {\"agent\" =\u003e \"foo\"})\n  # Passed records are stored into logger's internal buffer so don't re-post same event.\n  p log.last_error # You can get last error object via last_error method\nend\n\n# output: myapp.access {\"agent\":\"foo\"}\n```\n\n### Tag prefix\n```ruby\nrequire 'fluent-logger'\n\nlog = Fluent::Logger::FluentLogger.new('myapp', :host =\u003e 'localhost', :port =\u003e 24224)\nlog.post(\"access\", {\"agent\" =\u003e \"foo\"})\n\n# output: myapp.access {\"agent\":\"foo\"}\n```\n\n### Nonblocking write\n\n```ruby\nrequire 'fluent-logger'\n\nlog = Fluent::Logger::FluentLogger.new(nil, :host =\u003e 'localhost', :port =\u003e 24224, :use_nonblock =\u003e true, :wait_writeable =\u003e false)\n# When wait_writeable is false\nbegin\n  log.post(\"myapp.access\", {\"agent\" =\u003e \"foo\"})\nrescue IO::EAGAINWaitWritable =\u003e e\n  # wait code for avoding \"Resource temporarily unavailable\"\n  # Passed records are stored into logger's internal buffer so don't re-post same event.\nend\n\n# When wait_writeable is true\nunless log.post(\"myapp.access\", {\"agent\" =\u003e \"foo\"})\n  # same as other example\nend\n\n# output: myapp.access {\"agent\":\"foo\"}\n```\n\n### TLS setting\n\n```ruby\nrequire 'fluent-logger'\n\ntls_opts = {\n  :ca   =\u003e '/path/to/cacert.pem',\n  :cert =\u003e '/path/to/client-cert.pem',\n  :key  =\u003e '/path/to/client-key.pem',\n  :key_passphrase =\u003e 'test'\n}\nlog = Fluent::Logger::FluentLogger.new(nil, :host =\u003e 'localhost', :port =\u003e 24224, :tls_options =\u003e tls_opts)\n```\n\n`in_forward` config example:\n\n```\n\u003csource\u003e\n  @type forward\n  \u003ctransport tls\u003e\n    version TLS1_2\n    ca_path /path/to/cacert.pem\n    cert_path /path/to/server-cert.pem\n    private_key_path /path/to/server-key.pem\n    private_key_passphrase test\n    client_cert_auth true\n  \u003c/transport\u003e\n\u003c/source\u003e\n```\n\n### Singleton\n```ruby\nrequire 'fluent-logger'\n\nFluent::Logger::FluentLogger.open(nil, :host =\u003e 'localhost', :port =\u003e 24224)\nFluent::Logger.post(\"myapp.access\", {\"agent\" =\u003e \"foo\"})\n\n# output: myapp.access {\"agent\":\"foo\"}\n```\n\n### Logger options\n\n#### host (String)\n\nfluentd instance host\n\n#### port (Integer)\n\nfluentd instance port\n\n#### socket_path (String)\n\nIf specified, fluentd uses unix domain socket instead of TCP.\n\n#### nanosecond_precision (Bool)\n\nUse nano second event time instead of epoch. See also \"Tips\" section.\n\n#### use_nonblock (Bool)\n\nUse nonblocking write(`IO#write_nonblock`) instead of normal write(`IO#write`). If `Logger#post` stuck on your environment, specify `true`.  Default: `false`\n\n#### wait_writeable (Bool)\n\nIf `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`\n\n#### buffer_overflow_handler (Proc)\n\nPass callback for handling buffer overflow with pending data. See \"Buffer overflow\" section.\n\n#### tls_options (Hash)\n\nPass TLS related options.\n\n- use_default_ca: Set `true` if you want to use default CA\n- ca: CA file path\n- cert: Certificate file path\n- key: Private key file path\n- key_passphrase: Private key passphrase\n- version: TLS version. Default is `OpenSSL::SSL::TLS1_2_VERSION`\n- ciphers: The list of cipher suites. Default is `ALL:!aNULL:!eNULL:!SSLv2`\n- insecure: Set `true` when `in_forward` uses `insecure true`\n\n### Standard ::Logger compatible interface\n\n#### Example1\n\n```ruby\nrequire 'fluent-logger'\nf = Fluent::Logger::LevelFluentLogger.new('fluent')\n\nf.info(\"some application running.\")\n# output: fluent.info: {\"level\":\"INFO\",\"message\":\"some application running.\"}\n\nf.warn(\"some application running.\")\n# output: fluent.warn: {\"level\":\"WARN\",\"message\":\"some application running.\"}\n```\n\n#### Example2(add progname)\n\n```ruby\nrequire 'fluent-logger'\nf = Fluent::Logger::LevelFluentLogger.new('fluent')\nf.info(\"some_application\") {\"some application running.\"}\n# output: fluent.info: {\"level\":\"INFO\",\"message\":\"some application running.\",\"progname\":\"some_application\"}\n```\n\n#### Example3(set log level)\n\n```ruby\nrequire 'fluent-logger'\nf = Fluent::Logger::LevelFluentLogger.new('fluent')\nf.level = Logger::WARN\nf.info(\"some_application\") {\"some application running.\"}\n```\n\nLog level is ERROR so no output.\n\ndefault log level is debug.\n\n\n#### Example4(customize format for Rails)\n\n```ruby\nrequire 'fluent-logger'\nf = Fluent::Logger::LevelFluentLogger.new('fluent')\n\nf.formatter = proc do |severity, datetime, progname, message|\n  map = { level: severity }\n  map[:message] = message if message\n  map[:progname] = progname if progname\n  map[:stage] = ENV['RAILS_ENV']\n  map[:service_name] = \"SomeApp\"\n  map\nend\n\nf.info(\"some_application\"){\"some application running.\"}\n# output: fluent.info: {\"level\":\"INFO\",\"message\":\"some application running.\",\"progname\":\"some_application\",\"stage\":\"production\",\"service_name\":\"SomeApp\"}\n```\n\n## Loggers\n\n### Fluent\n```ruby\nFluent::Logger::FluentLogger.open('tag_prefix', :host =\u003e 'localhost', :port =\u003e 24224)\n```\n\n### Console\n```ruby\nFluent::Logger::ConsoleLogger.open(io)\n```\n\n### Null\n```ruby\nFluent::Logger::NullLogger.open\n```\n\n## Tips\n\n### Use nanosecond-precision time\n\nTo send events with nanosecond-precision time (Fluent 0.14 and up), specify `nanosecond_precision` to `FluentLogger` constructor.\n\n```ruby\nlog = Fluent::Logger::FluentLogger.new(nil, :host =\u003e 'localhost', :port =\u003e 24224, :nanosecond_precision =\u003e true)\n# Use nanosecond time instead\nlog.post(\"myapp.access\", {\"agent\" =\u003e \"foo\"})\nlog.post_with_time(\"myapp.access\", {\"agent\" =\u003e \"foo\"}, Time.now) # Need Time object for post_with_time\n```\n\n### Buffer overflow\n\nYou 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.\n\nYour 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.\n\n##### Example\n```ruby\nclass BufferOverflowHandler\n  attr_accessor :buffer\n\n  def flush(messages)\n    @buffer ||= []\n    MessagePack::Unpacker.new.feed_each(messages) do |msg|\n      @buffer \u003c\u003c msg\n    end\n  end\nend\n\nhandler = Proc.new { |messages| BufferOverflowHandler.new.flush(messages) }\n\nFluent::Logger::FluentLogger.new(nil,\n  :host =\u003e 'localhost', :port =\u003e 24224,\n  :buffer_overflow_handler =\u003e handler)\n```\n\n## Information\n\n|name|description|\n|---|---|\n|Web site|http://fluentd.org/ |\n|Documents|http://docs.fluentd.org/ |\n|Source repository|https://github.com/fluent/fluent-logger-ruby |\n|Author|Sadayuki Furuhashi|\n|Copyright|(c) 2011 FURUHASHI Sadayuki|\n|License|Apache License, Version 2.0|\n","funding_links":[],"categories":["Usage","Ruby"],"sub_categories":["Can be set fluent-logger instance in initialize parameters"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluent%2Ffluent-logger-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffluent%2Ffluent-logger-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluent%2Ffluent-logger-ruby/lists"}