collectiveidea / audited

Audited (formerly acts_as_audited) is an ORM extension that logs all changes to your Rails models.
MIT License
3.34k stars 645 forks source link

Exclude Audited Gem Log Entries from PostgreSQL Database Storage #687

Open hassan-righthand opened 8 months ago

hassan-righthand commented 8 months ago

Issue: We are currently using the Audited gem to handle audit logs in our Rails application. However, we have a specific use case where we do not want the audit logs generated by Audited to be stored in our PostgreSQL database. Instead, we are using an external source for our audit log storage.

# models/audit.rb
class Audit < Audited::Audit
  before_create :upload_logs
  after_initialize :set_user_details

  def upload_logs
    audit_adapter.upload_logs_to_external_source
  end

  def set_user_details
    audit_adapter.set_user_details
  end

  private

  def audit_adapter
    @audit_adapter ||= AuditAdapter.new(self)
  end
end

In the above code, we have a custom Audit model that inherits from Audited::Audit. We've implemented upload_logs and set_user_details methods to handle the upload of audit logs to an external source and setting user details, respectively.

Expected Outcome:

The goal is to configure Audited in a way that prevents it from storing any data in the PostgreSQL database, ensuring that all audit logs are exclusively stored in our external source.

Additional Context:

Note:

We are seeking guidance on how to configure Audited or if there is a recommended approach to achieve this outcome. Any assistance or suggestions would be greatly appreciated