Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Exceptionlog Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: The package provides a lightweight, structured way to log exceptions/errors in Laravel, complementing Laravel’s built-in logging (Monolog). It’s ideal for applications requiring persistent error tracking (e.g., debugging, SRE, or compliance needs) without heavy dependencies like Sentry or Bugsnag.
  • Layering: Acts as a log persistence layer, not a replacement for Monolog or Laravel’s Log facade. Integrates seamlessly with Laravel’s exception handling pipeline (App\Exceptions\Handler).
  • Data Model: Stores exceptions in a database table (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.
  • Extensibility: Hooks into Laravel’s register() method in AppServiceProvider, allowing for customization (e.g., adding metadata like user IDs, request data).

Integration Feasibility

  • Low Friction: Requires minimal setup—just publish the migration, configure the model, and optionally extend the ExceptionLog class.
  • Database Dependency: Assumes a Laravel-compatible database (MySQL, PostgreSQL, SQLite). No external services required.
  • Conflict Risk: Minimal with Laravel’s core, but may overlap with:
    • Custom exception handlers (e.g., render() methods in Handler.php).
    • Third-party monitoring tools (e.g., if using both this and Sentry, duplicate logs may occur).
  • Testing Overhead: Adds a new table and model; requires updating tests to account for logged exceptions.

Technical Risk

  • Stale Package: Last release in 2020 raises concerns about:
    • Compatibility with modern Laravel (v10+) or PHP (v8.2+).
    • Security vulnerabilities (though GPL-3.0 is permissive, unmaintained code is risky).
    • Missing features (e.g., no support for Laravel’s structured logging or PSR-3 adapters).
  • Performance: Logging to a database adds I/O overhead. For high-throughput apps, consider:
    • Batch inserts or queueing (e.g., queue:work).
    • Async logging (e.g., via Laravel Queues).
  • Data Retention: No built-in TTL or cleanup; requires manual table maintenance.

Key Questions

  1. Compatibility:
    • Has the package been tested with Laravel 10.x and PHP 8.2+? If not, what’s the migration effort?
    • Does it conflict with existing exception handlers or logging configurations?
  2. Functional Gaps:
    • Are there missing features (e.g., stack trace formatting, custom fields, or API endpoints for querying logs)?
    • How does it handle sensitive data (e.g., passwords in stack traces)? Is there redaction?
  3. Alternatives:
    • Would a custom Monolog handler or Laravel’s built-in logging suffice, or does this package add critical value?
    • Are there maintained alternatives (e.g., spatie/laravel-monitoring)?
  4. Operational Trade-offs:
    • What’s the impact of logging all exceptions (e.g., 404s, validation errors) vs. filtering (e.g., only 5xx errors)?
    • How will logs be queried/exported (e.g., for incident response)?

Integration Approach

Stack Fit

  • Laravel-Centric: Designed for Laravel’s ecosystem, leveraging:
    • Service providers (AppServiceProvider).
    • Eloquent models for persistence.
    • Laravel’s exception pipeline (report()/render()).
  • Database Agnostic: Works with any Laravel-supported DB, but schema must be manually published.
  • Limited External Dependencies: Only requires Laravel core and a database driver.

Migration Path

  1. Assessment Phase:
    • Audit existing exception handling (e.g., App\Exceptions\Handler).
    • Verify database compatibility (e.g., table engine, collation).
  2. Setup:
    • Publish the migration:
      php artisan vendor:publish --provider="AdrianoAlves\ExceptionLog\ExceptionLogServiceProvider"
      
    • Run the migration:
      php artisan migrate
      
    • Configure the ExceptionLog model (e.g., in config/exceptionlog.php).
  3. Integration:
    • Extend the 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'];
      }
      
    • Update App\Exceptions\Handler to log exceptions:
      public function report(Throwable $exception) {
          if (app()->bound('exceptionlog')) {
              app('exceptionlog')->log($exception);
          }
          parent::report($exception);
      }
      
  4. Testing:
    • Write tests for exception logging (e.g., using throw new Exception() in feature tests).
    • Verify logged data matches expectations (e.g., stack traces, timestamps).

Compatibility

  • Laravel Versions: Likely works with Laravel 5.x–9.x; test thoroughly for 10.x.
  • PHP Versions: May require PHP 7.4+ (check composer.json constraints).
  • Database: Supports MySQL, PostgreSQL, SQLite. Avoid edge cases like non-standard collations.
  • Conflict Mitigation:
    • If using Sentry/Bugsnag, disable duplicate logging in Handler.php.
    • For custom exception handlers, ensure report() calls are idempotent.

Sequencing

  1. Phase 1 (Core Integration):
    • Implement basic logging for all exceptions.
    • Validate data integrity (e.g., no missing stack traces).
  2. Phase 2 (Enhancements):
    • Add custom fields (e.g., user context, request data).
    • Implement filtering (e.g., log only errors, not warnings).
  3. Phase 3 (Operationalization):
    • Set up queries/alerts (e.g., "Alert on >10 5xx errors/minute").
    • Configure retention policies (e.g., archive logs to S3 after 30 days).

Operational Impact

Maintenance

  • Package Updates: None expected (abandoned repo). Fork or maintain locally if critical.
  • Schema Changes: Manual migrations required for future updates (if any).
  • Dependency Management:
    • Monitor for Laravel/PHP version conflicts.
    • Pin the package version in composer.json to avoid accidental updates.

Support

  • Debugging:
    • Logs provide a post-mortem tool but lack real-time monitoring.
    • Querying requires custom SQL or Eloquent (e.g., ExceptionLog::where('level', 'error')->get()).
  • Alerting:
    • No built-in integration with tools like PagerDuty. Requires custom scripts (e.g., cron jobs querying the table).
  • Sensitive Data:
    • Risk of logging PII (e.g., passwords in stack traces). Mitigate by:
      • Redacting data in ExceptionLog model events.
      • Using Laravel’s App\Exceptions\Handler to sanitize exceptions before logging.

Scaling

  • Performance:
    • Synchronous Logging: May bottleneck under high load. Mitigate with:
      • Database indexing on created_at, level.
      • Queueing logs (e.g., ExceptionLog::dispatch($exception)).
    • Async Alternative: Use Laravel Queues to defer logging:
      ExceptionLog::dispatch($exception)->onQueue('exceptions');
      
  • Storage:
    • Table growth: Monitor exception_logs size. Implement:
      • Partitioning (e.g., by month).
      • Archiving (e.g., export to S3/Glacier via cron).
  • Replication:
    • Read replicas can offload query load for analytics.

Failure Modes

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.

Ramp-Up

  • Onboarding Time: Low (1–2 days for basic setup).
    • Developers familiar with Laravel/Eloquent will adapt quickly.
  • Training Needs:
    • Document custom fields, query patterns, and alerting workflows.
    • Train ops teams on log retention/archiving.
  • Adoption Barriers:
    • Perception:
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope