Class: IronAdmin::AuditLog
- Inherits:
-
Object
- Object
- IronAdmin::AuditLog
- Defined in:
- lib/iron_admin/audit_log.rb
Overview
Audit logging system for tracking admin panel actions.
The AuditLog provides built-in tracking of create, update, and delete operations performed through the admin panel. It supports two storage backends: in-memory (default) and database.
Enabling Audit Logging
Enable in your initializer:
IronAdmin.configure do |config|
config.audit_enabled = true
config.audit_storage = :database # or :memory
end
For database storage, run the generator:
rails generate iron_admin:install_audit
rails db:migrate
Viewing Audit Logs
When enabled, audit logs are viewable at /admin/audit.
Defined Under Namespace
Classes: Entry
Class Method Summary collapse
-
.clear! ⇒ void
private
Clears all audit entries.
-
.database_storage_available? ⇒ Boolean
Checks if database storage is configured and available.
-
.entries ⇒ Array<Entry>
Returns all in-memory audit entries.
-
.log(event) ⇒ Entry, ...
Logs an audit event.
-
.query(filters = {}) ⇒ Array<Entry>, ActiveRecord::Relation
Queries audit entries with optional filters.
Class Method Details
.clear! ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Clears all audit entries.
147 148 149 150 |
# File 'lib/iron_admin/audit_log.rb', line 147 def clear! @entries = [] AuditEntry.delete_all if database_storage_available? end |
.database_storage_available? ⇒ Boolean
Checks if database storage is configured and available.
155 156 157 158 159 160 161 |
# File 'lib/iron_admin/audit_log.rb', line 155 def database_storage_available? IronAdmin.configuration.audit_storage == :database && defined?(AuditEntry) && AuditEntry.table_exists? rescue ActiveRecord::StatementInvalid, ActiveRecord::NoDatabaseError false end |
.entries ⇒ Array<Entry>
Returns all in-memory audit entries.
97 98 99 |
# File 'lib/iron_admin/audit_log.rb', line 97 def entries @entries ||= [] end |
.log(event) ⇒ Entry, ...
Logs an audit event.
Automatically routes to the configured storage backend (memory or database).
109 110 111 112 113 114 115 116 117 |
# File 'lib/iron_admin/audit_log.rb', line 109 def log(event) return unless IronAdmin.configuration.audit_enabled if database_storage_available? log_to_database(event) else log_to_memory(event) end end |
.query(filters = {}) ⇒ Array<Entry>, ActiveRecord::Relation
Queries audit entries with optional filters.
135 136 137 138 139 140 141 |
# File 'lib/iron_admin/audit_log.rb', line 135 def query(filters = {}) if database_storage_available? query_database(filters) else query_memory(filters) end end |