petritr/activity-log

Lightweight activity logging for Laravel applications

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/petritr/activity-log

v1.1.0 2026-01-21 20:13 UTC

This package is auto-updated.

Last update: 2026-01-21 21:39:52 UTC


README

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.

Installation

Install via Composer:

composer require petritr/activity-log

Publish the config file:

php artisan vendor:publish --tag=activity-log-config

Run migrations:

php artisan migrate

Configuration

The 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-logs

Config File Options:

config/activity-log.php:

return [
    // Enable/disable logging globally
    'enabled' => true,

    // Enable/disable logging via queue
    'queue_enabled' => false,
];

Usage

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();

Subject Snapshots

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.

Queue Support

Enable queueing in config/activity-log.php:

'queue_enabled' => true,

Your activity will be dispatched to the queue using a Laravel Job.

License

MIT License.