{"id":15431842,"url":"https://github.com/nowlinuxing/kushojin","last_synced_at":"2026-05-06T09:33:19.103Z","repository":{"id":55446525,"uuid":"96926249","full_name":"nowlinuxing/kushojin","owner":"nowlinuxing","description":"Send and record changes of ActiveRecord models via Fluentd","archived":false,"fork":false,"pushed_at":"2022-08-23T07:50:01.000Z","size":78,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-25T05:05:54.785Z","etag":null,"topics":["activerecord","fluentd","ruby","ruby-on-rails"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nowlinuxing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-11T18:54:15.000Z","updated_at":"2022-01-25T08:00:36.000Z","dependencies_parsed_at":"2022-08-15T00:30:44.636Z","dependency_job_id":null,"html_url":"https://github.com/nowlinuxing/kushojin","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nowlinuxing%2Fkushojin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nowlinuxing%2Fkushojin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nowlinuxing%2Fkushojin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nowlinuxing%2Fkushojin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nowlinuxing","download_url":"https://codeload.github.com/nowlinuxing/kushojin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243132194,"owners_count":20241359,"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":["activerecord","fluentd","ruby","ruby-on-rails"],"created_at":"2024-10-01T18:24:15.503Z","updated_at":"2025-12-16T08:41:42.134Z","avatar_url":"https://github.com/nowlinuxing.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kushojin\n\n[![Gem Version](https://badge.fury.io/rb/kushojin.svg)](https://badge.fury.io/rb/kushojin)\n[![CI](https://github.com/nowlinuxing/kushojin/workflows/CI/badge.svg)](https://github.com/nowlinuxing/kushojin/actions)\n[![Maintainability](https://api.codeclimate.com/v1/badges/33c293ed9b4f9f25ab2c/maintainability)](https://codeclimate.com/github/nowlinuxing/kushojin/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/33c293ed9b4f9f25ab2c/test_coverage)](https://codeclimate.com/github/nowlinuxing/kushojin/test_coverage)\n\nKushojin gathers changes to the attributes of the ActiveRecord model and sends them externally via Fluentd.\nThis is useful for logging, tracking and real-time aggregation of accesses involving database updates.\nSince Fluentd is used for external transmission, Kushojin can respond flexibly to various requests.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'kushojin'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install kushojin\n\n## Usage\n\n```ruby\nKushojin::Config.logger = Fluent::Logger::FluentLogger.new(nil, host: \"localhost\", port: 24224)\n\nclass User \u003c ApplicationRecord\n  record_changes\nend\n\nclass UsersController \u003c ApplicationController\n  send_changes\n\n  def create\n    User.create(params[:user])\n  end\nend\n```\n\n    $ curl -X POST -d \"user[name]=bill\u0026user[age]=20\" http://localhost:3000/users\n    # output: users.create {\"event\":\"create\",\"request_id\":\"4afd0731-dd25-4668-b769-2017dbdd3642\",\"table_name\":\"users\",\"id\":1,\"changes\":{\"name\":[null,\"bill\"],\"age\":[null,20]}}\n\nChanges is recorded when the model is created, updated and destroyed.\nThe `:only` option can be used same as filters of controller.\n\n```ruby\nclass User \u003c ApplicationRecord\n  record_changes only: [:create, :destroy]\nend\n```\n    $ curl -X POST -d \"user[name]=bill\u0026user[age]=20\" http://localhost:3000/users\n    # output: users.create {\"event\":\"create\",\"request_id\":\"4afd0731-dd25-4668-b769-2017dbdd3642\",\"table_name\":\"users\",\"id\":1,\"changes\":{\"name\":[null,\"bill\"],\"age\":[null,20]}}\n\n    $ curl -X PATCH -d \"user[age]=21\" http://localhost:3000/users/1\n    # no output\n\n### Customize sending fields of changes\n\nKushojin sends model changes with some information:\n\n- tag: Controller name and action name concatenated with a period.\n- event: The event which model is changed on.\n- table_name: Table name of the model.\n- primary key: Primary key name and value.\n- changes: Model changes without its primary key, `created_at`, and `updated_at`. It contains pairs of attribute name and before/after values.\n- request_id: Request ID.\n\nIt is able to pass a customized sender to add additional information.\n\n```ruby\nclass CustomSender \u003c Kushojin::Sender::EachSender\n  private\n\n  # Add \"user_id\"\n  def serialize(change, controller)\n    super.merge!(\"user_id\" =\u003e controller.current_user.id)\n  end\nend\n\nclass MessagesController \u003c ApplicationController\n  send_changes Kushojin::ControllerMethods::SendChangeCallback.new(sender: CustomSender.new)\n\n  def current_user\n    return_user_record_with_any_authentication_logic\n  end\n\n  def create\n    Message.create(params[:message])\n  end\nend\n```\n\n### Customize callbacks of model\n\nYou can pass in a class or an instance to change behaviors of the callbacks.\n\n```ruby\nclass CustomCallbacks\n  # Must be able to respond to after_create, after_update, and after_destroy.\n  def after_create(record); end\n  def after_update(record); end\n  def after_destroy(record); end\nend\n\nclass User \u003c ApplicationRecord\n  record_changes CustomCallbacks.new\nend\n```\n\n\n### Override\n\nYou can override options of Recording changes in subclass.\n\n```ruby\nclass ApplicationRecord \u003c ActiveRecord::Base\n  self.abstract_class = true\n  record_changes\nend\n\nclass User \u003c ApplicationRecord\n  record_changes only: [:create, :destroy]\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/nowlinuxing/kushojin.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnowlinuxing%2Fkushojin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnowlinuxing%2Fkushojin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnowlinuxing%2Fkushojin/lists"}