{"id":19788349,"url":"https://github.com/graylog2/graylog-guide-rails","last_synced_at":"2025-10-06T02:45:29.178Z","repository":{"id":137547629,"uuid":"44181724","full_name":"Graylog2/graylog-guide-rails","owner":"Graylog2","description":"Guide about how to get Ruby On Rails logs into Graylog","archived":false,"fork":false,"pushed_at":"2020-08-13T13:20:41.000Z","size":8,"stargazers_count":27,"open_issues_count":1,"forks_count":5,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-01-11T03:49:11.949Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Graylog2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-13T14:24:46.000Z","updated_at":"2024-12-17T18:39:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"bef1cc4d-4bdc-40b5-a1bb-1a6f060ce1a8","html_url":"https://github.com/Graylog2/graylog-guide-rails","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graylog2%2Fgraylog-guide-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graylog2%2Fgraylog-guide-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graylog2%2Fgraylog-guide-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graylog2%2Fgraylog-guide-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Graylog2","download_url":"https://codeload.github.com/Graylog2/graylog-guide-rails/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241125008,"owners_count":19913839,"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":[],"created_at":"2024-11-12T06:26:56.645Z","updated_at":"2025-10-06T02:45:24.146Z","avatar_url":"https://github.com/Graylog2.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"### Logging from a Ruby on Rails application to a Graylog server\n\nThis guide briefly describes the steps required to send logs from your Ruby on Rails application to a Graylog server. **The Rails version used in this guide is v4.2.1.** but should work with different versions, too.\n\n#### Overview\n\nWe'll be using [the official Graylog GELF gem](https://github.com/Graylog2/gelf-rb) to transport messages formatted by [the lograge gem](https://github.com/roidrage/lograge). The reason to use lograge is that Rails has a default logger that is very noisy and splits up messages over multiple lines. Lograge does a great job taming the format and provides a `key=value` formatter that we can use to extract fields in Graylog later.\n\n#### Configure Graylog\n\nWe provide a Graylog content pack that starts the correct GELF input type together with extractors (parser rules) to make the configuration really easy. [Just apply this content pack using your Graylog Web Interface](https://marketplace.graylog.org/addons/0a1caed3-92a5-4f86-840b-2c61421d73dc) and follow the next steps in this guide.\n\n#### Configuring your Rails application\n\nAdd the two gems to your `Gemfile`:\n\n    gem 'gelf'\n    gem 'lograge'\n    \nIn your `config/environment/development.rb` (and `production.rb`) set up Rails to log to your Graylog server:\n\n    config.logger = GELF::Logger.new(\"graylog.example.org\", 12219, \"WAN\", { :facility =\u003e \"YOUR_APP_NAME\" })\n\n\u003e You may need to manually include the silencer module to your GELF logger to avoid `NoMethodError (undefined method 'silence_logger' for #\u003cGELF::Logger:0x0000000007f5f170\u003e)`:\n\u003e ```ruby\n\u003e   GELF::Logger.send :include, ActiveRecord::SessionStore::Extension::LoggerSilencer\n\u003e   config.logger = GELF::Logger.new(...)\n\u003e ```\n\u003e \n\u003e This silencer is being used to silence the logger and not leaking private information into the log, and it is required for security reason.\n\n\nCreate a new initializer (`config/initializers/lograge.rb`) to configure the lograge formatting:\n\n    Rails.application.configure do\n      config.lograge.enabled = true\n      config.lograge.formatter = Lograge::Formatters::KeyValue.new\n    end\n    \nYour Rails application should now log into the Graylog input the content pack launched and already apply proper parsing of the message content into fields.\n    \n#### Custom events\n\nThe above steps forward the standard built-in Rails logs to Graylog in realtime. Any explicit call to `logger` will also be sending to Graylog, but without the lograge formatting applied:\n\n    logger.info(\"A new user with id \u003c#{user.id}\u003e signed up.\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraylog2%2Fgraylog-guide-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraylog2%2Fgraylog-guide-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraylog2%2Fgraylog-guide-rails/lists"}