sergeahouansinou / laravel-exception-tracker
A simple self-hosted Laravel package for tracking and logging exceptions in your projects.
Package info
github.com/sergeahouansinou/laravel-exception-tracker
Language:Blade
pkg:composer/sergeahouansinou/laravel-exception-tracker
Requires
- php: ^8.2
- illuminate/support: ^12.0
Requires (Dev)
- fakerphp/faker: ^1.23
- laravel/framework: ^12.0
- laravel/pail: ^1.2
- laravel/pint: ^1.13
- laravel/sail: ^1.31
- mockery/mockery: ^1.6
- nunomaduro/collision: ^8.1
- phpunit/phpunit: ^11.0.1
This package is auto-updated.
Last update: 2026-04-16 13:19:33 UTC
README
A self-hosted Laravel package for tracking and logging exceptions with automatic email notifications. Inspired by Sentry, but 100% under your control โ no data sent to third parties.
โจ Features
- ๐ฆ Automatic exception capture via Laravel's
reportable()hook โ never replaces the existing Handler - ๐พ Database storage in a dedicated
exception_logstable - ๐ฌ Professional HTML email notifications with a Sentry-inspired template
- ๐ Sensitive data filtering (passwords, tokens, secrets masked automatically)
- โ๏ธ Configurable exception filtering โ ignore ValidationException, AuthenticationException, etc.
- ๐ Async email sending via Laravel queues (non-blocking)
- ๐งน Artisan command to purge old logs
- ๐ก REST API to consult exception logs
- ๐งฐ Compatible with Laravel 9 to 12
๐ Requirements
- PHP >= 8.0
- Laravel 9, 10, 11, or 12
- A configured database connection (MySQL, PostgreSQL, SQLite, etc.)
- A configured mail driver (for email notifications)
๐ Quick Start โ Adding to a Laravel Project
Follow these steps to integrate Laravel Exception Tracker into a new or existing Laravel project.
Step 1 โ Create a Laravel project (skip if you already have one)
composer create-project laravel/laravel my-project
cd my-project
Step 2 โ Install the package via Composer
composer require sergeahouansinou/laravel-exception-tracker
Auto-discovery: The service provider (
ExceptionTrackerServiceProvider) is registered automatically via Laravel's package auto-discovery. No manual registration inconfig/app.phpis needed.
Step 3 โ Publish configuration and views
php artisan vendor:publish --tag=exception-tracker-config php artisan vendor:publish --tag=exception-tracker-views
Step 4 โ Run migrations
php artisan migrate
This creates the exception_logs table in your database.
Step 5 โ Configure your .env
Add the following variables to your .env file:
# Exception Tracker EXCEPTION_TRACKER_ENABLED=true EXCEPTION_TRACKER_EMAIL_ENABLED=true EXCEPTION_TRACKER_RECIPIENTS=admin@example.com,dev@example.com EXCEPTION_TRACKER_QUEUE_ENABLED=true EXCEPTION_TRACKER_QUEUE_CONNECTION=null EXCEPTION_TRACKER_QUEUE_NAME=default
Note: By default, tracking is disabled in the
localandtestingenvironments. To enable it locally, removelocalfrom thedisabled_environmentsarray inconfig/exception-tracker.php.
Step 6 โ Configure mail (for email notifications)
Make sure your Laravel project has a working mail driver configured in .env:
MAIL_MAILER=smtp MAIL_HOST=smtp.example.com MAIL_PORT=587 MAIL_USERNAME=your@email.com MAIL_PASSWORD=your-password MAIL_ENCRYPTION=tls MAIL_FROM_ADDRESS=no-reply@example.com MAIL_FROM_NAME="${APP_NAME}"
Step 7 โ (Optional) Start a queue worker for async emails
If EXCEPTION_TRACKER_QUEUE_ENABLED=true (the default), emails are sent via a Laravel queue. Start a worker to process them:
php artisan queue:work
That's it! Laravel Exception Tracker is now active. Any unhandled exception in your application will be automatically captured, stored in the database, and reported by email.
โ๏ธ Installation
1. Install via Composer
composer require sergeahouansinou/laravel-exception-tracker
2. Publish configuration and views
php artisan vendor:publish --tag=exception-tracker-config php artisan vendor:publish --tag=exception-tracker-views
3. Run migrations
php artisan migrate
4. Configure your .env
EXCEPTION_TRACKER_ENABLED=true EXCEPTION_TRACKER_EMAIL_ENABLED=true EXCEPTION_TRACKER_RECIPIENTS=admin@example.com,dev@example.com EXCEPTION_TRACKER_QUEUE_ENABLED=true EXCEPTION_TRACKER_QUEUE_CONNECTION=null EXCEPTION_TRACKER_QUEUE_NAME=default
๐ ๏ธ Configuration
The published config file (config/exception-tracker.php) supports:
| Option | Description | Default |
|---|---|---|
enabled |
Enable/disable exception tracking | true |
email_enabled |
Enable/disable email notifications | true |
recipients |
List of email addresses to notify | [] |
queue.enabled |
Send emails via queue (async) | true |
queue.connection |
Queue connection name | null |
queue.queue |
Queue name | default |
ignored_exceptions |
Exception classes to skip | ValidationException, AuthenticationException, etc. |
disabled_environments |
Environments where tracking is disabled | ['local', 'testing'] |
sensitive_fields |
Fields to mask in request data | ['password', 'token', 'secret', ...] |
stack_trace_limit |
Max stack trace frames | 20 |
max_days |
Days to retain logs | 30 |
๐ง Email Template
The email template is a professional, responsive HTML design inspired by Sentry, with clear sections:
- Error Summary โ Exception class, message, file and line
- Stack Trace โ Formatted, limited, monospace display
- Request Details โ URL, method, IP address
- Request Headers & Body โ With sensitive data masked
- Authenticated User โ ID and email
- Environment โ App name, environment, PHP/Laravel versions, server, timestamp, request ID
The template is publishable and fully customizable:
php artisan vendor:publish --tag=exception-tracker-views
๐ Usage
Automatic Capture
The package hooks into Laravel's exception handler via reportable(). All unhandled exceptions are automatically captured and reported โ no code changes needed.
Manual Tracking
use ExceptionTracker\ExceptionTracker; try { // risky operation } catch (\Throwable $e) { ExceptionTracker::handle($e); }
Or use the helper function:
exception_tracker_log($e);
Middleware (Optional)
For route-specific tracking:
use ExceptionTracker\Http\Middleware\TrackExceptions; Route::middleware(TrackExceptions::class)->group(function () { // your routes });
๐ก REST API
GET /api/exception-trackerโ List exception logs (paginated)GET /api/exception-tracker/{id}โ Get a single exception log
๐งน Artisan Commands
# Purge old exception logs
php artisan exception-tracker:clear
๐๏ธ Architecture
| Class | Role |
|---|---|
ExceptionTrackerServiceProvider |
Registers config, views, migrations, routes, commands, and hooks into reportable() |
ExceptionTracker |
Orchestrator โ filters, builds payload, stores, and notifies |
PayloadBuilder |
Builds structured error payloads with HTTP context, user, and environment |
ExceptionOccurred |
Mailable class for sending HTML email notifications |
ExceptionLog |
Eloquent model for the exception_logs table |
TrackExceptions |
Middleware for route-specific exception tracking |
๐ Security & Performance
- Fail-safe: All internal errors are caught and logged โ never crashes the host application
- Non-blocking: Email sending via Laravel queues by default
- Data privacy: Sensitive fields (passwords, tokens, secrets) are masked automatically
- No host modification: Uses
reportable()โ never replaces or wraps the Laravel exception handler
๐ Packagist Auto-Deployment
This repository is configured to automatically notify Packagist whenever a commit is pushed to main/master or a new release is published, so the package is always up to date.
Required GitHub Secrets
Add the following secrets to your GitHub repository (Settings โ Secrets and variables โ Actions):
| Secret | Description |
|---|---|
PACKAGIST_USERNAME |
Your Packagist username |
PACKAGIST_TOKEN |
Your Packagist API token (found on your Packagist profile) |
Once these secrets are set, every push to main/master and every published release will automatically trigger a Packagist package update.
๐ License
MIT License. See LICENSE for details.