justbetter/laravel-error-logger
Manually log application errors to a database with a fluent API (message, details, group, throwable, model). Optionally schedule a daily notification job to send summaries via a chosen channel (e.g. Slack). Includes pruning command; Nova UI available separately.
App\Exceptions\Handler, this package does not auto-capture exceptions. Requires explicit ErrorLogger::log() calls, increasing boilerplate.LogError::withContext()).ErrorNotificationJob for daily digests, with no support for real-time alerts or multi-channel (e.g., email + Slack) out-of-the-box.App\Exceptions\Handler.php for manual logging).justbetter/nova-error-logger (separate package), adding dependency complexity.errors table with fields like message, context (JSON), level, and created_at.App\Exceptions\Handler::render() or via middleware (e.g., LogErrorMiddleware).ErrorNotificationJob or use Laravel’s event system to broadcast errors elsewhere.errors table, impacting query performance.laravel-error-logger:prune command and archive old data (e.g., to cold storage).context JSON?App\Exceptions\Handler, custom loggers).php artisan vendor:publish --provider="JustBetter\ErrorLogger\ServiceProvider"
php artisan migrate
.env for notification channels (e.g., LARAVEL_ERROR_NOTIFICATION_CHANNEL=slack).App\Exceptions\Handler::render() to log exceptions:
public function render($request, Throwable $exception)
{
ErrorLogger::log($exception)->withContext(['user_id' => auth()->id()]);
return parent::render($request, $exception);
}
public function handle($request, Closure $next)
{
try {
return $next($request);
} catch (Throwable $e) {
ErrorLogger::log($e);
throw $e;
}
}
App\Console\Kernel.php:
$schedule->job(ErrorNotificationJob::class)->dailyAt('09:00');
.env or service provider bindings.justbetter/nova-error-logger and publish its assets if using Nova.composer.json for exact requirements).php -v).mail, discord channels).laravel-error-logger:prune via cron).errors table schema evolves.errors table; query with:
SELECT * FROM errors ORDER BY created_at DESC LIMIT 100;
DB::insert) can optimize bulk operations.errors table may slow with >100K entries. Index created_at and level fields:
Schema::table('errors', function (Blueprint $table) {
$table->index('created_at');
$table->index('level');
});
- **Archiving**: Use the prune command or archive old logs to a separate table/DB.
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Database connection issues | Logs lost if writes fail silently. | Use Laravel’s try-catch in logging calls. |
| Scheduler downtime | Missed daily notifications. | Monitor scheduled:run command; use external cron. |
| Manual logging overs |
How can I help you explore Laravel packages today?