A small high-performance activity logging package for Laravel.
Easily track user actions, record model changes via polymorphic subjects, and store custom metadata. Designed for simplicity and flexibility, it supports both synchronous and asynchronous (queued) logging out of the box.
Key Features:
- Fluent API: Log activities using a clean, readable facade.
- Polymorphic Subjects: Link activities to any Eloquent model automatically.
- Data Snapshots: Automatically capture specific model attributes at the time of logging.
- Queue Support: Offload logging to background workers for better application performance.
- Customizable: Configurable fields, silent failure options, and more.
Install via Composer:
composer require petritr/activity-logPublish the config file:
php artisan vendor:publish --tag=activity-log-configRun migrations:
php artisan migrateThe package comes with a default configuration. You can customize it in config/activity-log.php.
You can also use environment variables in your .env file:
ACTIVITY_LOG_ENABLED=true
ACTIVITY_LOG_QUEUE_ENABLED=false
ACTIVITY_LOG_QUEUE=activity-logsconfig/activity-log.php:
return [
// Enable/disable logging globally
'enabled' => true,
// Enable/disable logging via queue
'queue_enabled' => false,
];Using the Facade (recommended)
use Petritr\ActivityLog\Facades\ActivityLog;
// Log a simple action
ActivityLog::action('user.login')->log();
// Log with a subject
ActivityLog::action('project.updated')
->subject($project)
->log();
// Log with metadata
ActivityLog::action('order.created')
->withMetadata(['total' => 99.90, 'items' => ['apple', 'banana']])
->log();You can log a snapshot of any model or object:
ActivityLog::action('user.updated')
->subject($user)
->log();
The snapshot is stored in JSON format (subject_snapshot) in the database.
Enable queueing in config/activity-log.php:
'queue_enabled' => true,Your activity will be dispatched to the queue using a Laravel Job.
MIT License.