Search code examples
ruby-on-railsacts-as-audited

Automatic logging to file with Audited gem


Using the Rails Audited gem, I would like to also have a friendly, human readable log file that has all the updates.

Is there a way to easily do that?


Solution

  • You could leverage this option from the doc:

    class CustomAudit < Audited::Audit
      after_commit :custom_log
    
      def custom_log
        # do what you need here with attributes
      end
    end
    
    # Then set it in an initializer like config/initializers/audited.rb
    Audited.config do |config|
      config.audit_class = CustomAudit
    end