adrianoalves/laravel-exceptionlog
Minimal Laravel 7+ package to persist exceptions to a database logs table. Install via Composer, migrate, then call ExceptionLog::persist($exception, $level). Includes simple level mapper (app, DB, server, console, jobs) and is customizable.
Log facade. Integrates seamlessly with Laravel’s exception handling pipeline (App\Exceptions\Handler).exception_logs), enabling querying (e.g., "Find all 5xx errors in the last 24 hours"). Useful for observability but lacks advanced features like alerting or user context enrichment.register() method in AppServiceProvider, allowing for customization (e.g., adding metadata like user IDs, request data).ExceptionLog class.render() methods in Handler.php).queue:work).spatie/laravel-monitoring)?AppServiceProvider).report()/render()).App\Exceptions\Handler).php artisan vendor:publish --provider="AdrianoAlves\ExceptionLog\ExceptionLogServiceProvider"
php artisan migrate
ExceptionLog model (e.g., in config/exceptionlog.php).ExceptionLog class to add custom fields (e.g., user_id, request_ip):
namespace App\Exceptions;
use AdrianoAlves\ExceptionLog\ExceptionLog as BaseExceptionLog;
class ExceptionLog extends BaseExceptionLog {
protected $fillable = ['user_id', 'request_ip'];
}
App\Exceptions\Handler to log exceptions:
public function report(Throwable $exception) {
if (app()->bound('exceptionlog')) {
app('exceptionlog')->log($exception);
}
parent::report($exception);
}
throw new Exception() in feature tests).composer.json constraints).Handler.php.report() calls are idempotent.composer.json to avoid accidental updates.ExceptionLog::where('level', 'error')->get()).ExceptionLog model events.App\Exceptions\Handler to sanitize exceptions before logging.created_at, level.ExceptionLog::dispatch($exception)).ExceptionLog::dispatch($exception)->onQueue('exceptions');
exception_logs size. Implement:
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Database downtime | Lost exception logs | Queue logs locally; retry on recovery. |
| Unhandled exceptions | Logs may miss critical errors | Ensure Handler::report() always calls the logger. |
| Schema corruption | Query failures | Regular backups; test migrations. |
| Resource exhaustion (CPU/DB) | Slow logging | Rate-limiting; async processing. |
| Sensitive data leakage | GDPR/privacy violations | Redact logs; audit stack traces. |
How can I help you explore Laravel packages today?