PHPackages                             logforge/logforge-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. logforge/logforge-laravel

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

logforge/logforge-laravel
=========================

LogForge: Unified audit logging for Laravel (create/update/delete with diffs, actor, context).

0.1.0(7mo ago)02MITPHPPHP &gt;=8.0

Since Sep 30Pushed 7mo agoCompare

[ Source](https://github.com/Ycrafts/logforge-laravel)[ Packagist](https://packagist.org/packages/logforge/logforge-laravel)[ RSS](/packages/logforge-logforge-laravel/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

LogForge Laravel
================

[](#logforge-laravel)

Unified audit logging for Laravel: automatically log create, update, delete (plus restore/force\_delete) with diffs, actor, and minimal context.

Install
-------

[](#install)

1. Require the package (once published to Packagist):

```
composer require logforge/logforge-laravel
```

2. Publish config and migrations:

```
php artisan vendor:publish --tag=logforge-config
php artisan vendor:publish --tag=logforge-migrations
```

3. Run migrations:

```
php artisan migrate
```

**Note:** The audit\_logs migration is designed to run last (timestamp: 2025-12-31 23:59:59) to ensure all user and resource tables exist before creating foreign key constraints.

Configure
---------

[](#configure)

Edit `config/logforge.php`.

- `enabled`: turn logging on/off
- `events`: \['create','update','delete','restore','force\_delete'\]
- `include`/`exclude`/`redact`: global attribute controls
- `per_model[Your\Model::class]`: per-model include/exclude/redact
- `context.capture_ip` / `context.capture_user_agent`
- `payload_max_bytes`, `suppress_exceptions`, `actor.resolver`
- `writer`: 'db' (default, synchronous) or 'queue' (asynchronous)
- `queue`: connection, queue name, delay settings

ENV overrides:

- `LOGFORGE_ENABLED`, `LOGFORGE_SNAPSHOT_ON_UPDATE`, `LOGFORGE_PAYLOAD_MAX_BYTES`, `LOGFORGE_SUPPRESS_EXCEPTIONS`
- `LOGFORGE_RETENTION_DAYS`, `LOGFORGE_ARCHIVE_ENABLED`, `LOGFORGE_ARCHIVE_PATH`
- `LOGFORGE_WRITER`, `LOGFORGE_QUEUE_CONNECTION`, `LOGFORGE_QUEUE_NAME`, `LOGFORGE_QUEUE_DELAY`

Writer Options
--------------

[](#writer-options)

### Database Writer (Default)

[](#database-writer-default)

- **`writer => 'db'`**: Synchronous database writes
- **Pros**: Works immediately, no setup required, guaranteed delivery
- **Cons**: Slower response times, blocks user request
- **Best for**: Development, testing, low-volume production

### Queue Writer (Recommended for Production)

[](#queue-writer-recommended-for-production)

- **`writer => 'queue'`**: Asynchronous queue-based writes
- **Pros**: Better performance, non-blocking, scalable
- **Cons**: Requires queue worker, potential for lost logs if worker fails
- **Best for**: High-volume production environments

#### Setting Up Queue Writer

[](#setting-up-queue-writer)

1. **Change configuration:**

    ```
    // config/logforge.php
    'writer' => 'queue',
    ```
2. **Start queue worker:**

    ```
    php artisan queue:work
    ```
3. **Or use database queue:**

    ```
    php artisan queue:table
    php artisan migrate
    php artisan queue:work
    ```

**⚠️ Important**: Queue writer requires a queue worker to be running. If no worker is active, audit logs won't be written.

Use
---

[](#use)

Add the trait to any Eloquent model:

```
use LogForge\Laravel\Audit\Traits\LogsActivity;

class Post extends Model
{
    use LogsActivity;
}
```

On create/update/delete/restore/forceDelete, an `audit_logs` row is written with:

- event\_type, user\_id, resource\_type, resource\_id
- data (diffs/snapshots), ip\_address, context (user\_agent)

**Note:** By default, logs are written synchronously to the database for immediate results. For better performance, set `LOGFORGE_WRITER=queue` and ensure your queue worker is running.

### Update event payload example

[](#update-event-payload-example)

For updates, `data` stores a before/after diff of changed fields:

```
{
  "old": { "title": "Old title", "status": "draft" },
  "new": { "title": "New title", "status": "published" }
}
```

If full snapshots are enabled (`snapshot_on_update=true`), the `new` section also includes a `__full` key:

```
{
  "old": { "title": "Old title" },
  "new": {
    "title": "New title",
    "__full": { "id": 123, "title": "New title", "status": "published" }
  }
}
```

Example model
-------------

[](#example-model)

See `examples/ExamplePost.php` for a minimal example using `SoftDeletes` and `LogsActivity`.

Maintenance
-----------

[](#maintenance)

### Pruning old logs

[](#pruning-old-logs)

Remove old audit logs to manage storage:

```
# Use configured retention_days
php artisan logforge:prune

# Override retention period
php artisan logforge:prune --days=30

# Archive before deleting (creates timestamped JSON file)
php artisan logforge:prune --archive
```

Archive files are saved to `storage/logs/logforge/` by default (configurable via `LOGFORGE_ARCHIVE_PATH`).

Archive format:

```
{
  "metadata": {
    "pruned_at": "2025-01-28T14:30:22.000000Z",
    "retention_days": 30,
    "cutoff_date": "2024-12-29T14:30:22.000000Z",
    "records_count": 150,
    "format": "json"
  },
  "records": [...]
}
```

Performance monitoring (optional)
---------------------------------

[](#performance-monitoring-optional)

Enable lightweight performance diagnostics to spot bottlenecks:

ENV:

```
LOGFORGE_PERF_ENABLED=true
LOGFORGE_PERF_SLOW_MS=100   # warn if an audit takes >= 100ms
LOGFORGE_PERF_SAMPLE=1.0    # sample rate 0..1 (1.0 = all)

```

Behavior:

- Measures total time and splits build\_ms vs write\_ms.
- Emits a structured warning when total\_ms &gt;= threshold.
- Uses Laravel’s default logger (e.g., storage/logs/laravel.log) and respects your logging channels.

Example log payload:

```
{
  "event_type": "update",
  "model_class": "App\\Models\\Post",
  "model_key": "123",
  "total_ms": 142,
  "build_ms": 35,
  "write_ms": 107
}
```

Notes
-----

[](#notes)

- Fail-safe: DB write failures are suppressed (configurable) and logged.
- JSON: uses JSON column; ensure your DB supports it (MySQL 5.7+, PostgreSQL, SQLite JSON via TEXT).
- Extensibility: config supports per-model overrides; writer abstraction can be added later for queues/streams.
- Archive: Enable automatic archiving via `LOGFORGE_ARCHIVE_ENABLED=true` in your `.env`.
- Queue: Default synchronous logging via database. For asynchronous logging, set `LOGFORGE_WRITER=queue` and ensure queue worker is running. Jobs are retried up to 3 times with 30-second timeout.

Enable Dashboard (config only)
------------------------------

[](#enable-dashboard-config-only)

The dashboard is disabled by default. To enable routes like `/logforge/logs`, set:

```
LOGFORGE_DASHBOARD_ENABLED=true

```

Optional (defaults shown):

```
LOGFORGE_DASHBOARD_PATH=logforge

```

Note: When enabling, ensure your app’s authentication is set up (web session login) and protect access according to your needs (e.g., Gate).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance63

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

230d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/715f72c3496a1142a0abc51964e6dba6b6c30db2b789905ecc76a9fe659985a1?d=identicon)[Ycrafts](/maintainers/Ycrafts)

---

Top Contributors

[![Ycrafts](https://avatars.githubusercontent.com/u/101559690?v=4)](https://github.com/Ycrafts "Ycrafts (7 commits)")

---

Tags

laravelloggingAuditactivity-logcompliance

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/logforge-logforge-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/logforge-logforge-laravel/health.svg)](https://phpackages.com/packages/logforge-logforge-laravel)
```

###  Alternatives

[masterro/laravel-mail-viewer

Easily view in browser outgoing emails.

6392.1k](/packages/masterro-laravel-mail-viewer)[muhammadsadeeq/laravel-activitylog-ui

A beautiful, modern UI for Spatie's Activity Log with advanced filtering, analytics, and real-time features.

17510.1k](/packages/muhammadsadeeq-laravel-activitylog-ui)[iamfarhad/laravel-audit-log

Comprehensive entity-level audit logging package for Laravel applications with model-specific tables, field exclusion, and batch processing support

1315.6k](/packages/iamfarhad-laravel-audit-log)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
