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 Auditing Log Laravel Package

onramplab/laravel-auditing-log

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Complementary to Existing Auditing Needs: The package integrates with spatie/laravel-activitylog, a well-established auditing solution, offering an additional layer of structured logging. This aligns well with systems requiring immutable audit trails (e.g., financial, healthcare, or compliance-sensitive applications).
  • Event-Driven Extension: Leverages Laravel’s event system to append metadata (e.g., timestamps, user context) to existing activity logs, reducing redundancy in custom audit logic.
  • Database Agnostic: Relies on doctrine/dbal for database abstraction, ensuring compatibility with MySQL, PostgreSQL, SQLite, etc., without vendor lock-in.

Integration Feasibility

  • Low-Coupling Design: The package adheres to PSR-4/PSR-2 standards, minimizing friction in monorepos or multi-package projects. Its modular structure allows selective adoption (e.g., enabling only for critical models).
  • Dependency Overlap: Requires spatie/laravel-activitylog (v4.7+), which may necessitate version alignment if the project already uses an older version. Conflict risk is mitigated by Laravel’s autoloader isolation.
  • Configuration Override: Supports customizing log fields via Laravel’s config, enabling tailored audit schemas without core modifications.

Technical Risk

  • Dependency Maturity: spatie/laravel-activitylog is production-ready, but the wrapper package (laravel-auditing-log) has no dependents and a single-star repo, raising concerns about:
    • Long-term maintenance (last release: 2023-03-30).
    • Undiscovered edge cases in event listeners or database writes.
  • Performance Impact: Audit logs add write overhead to critical paths (e.g., user actions). Benchmarking is required to validate latency in high-throughput systems.
  • Data Retention: No built-in TTL or archival mechanism; requires custom logic for log purging (e.g., via Laravel’s schedule).

Key Questions

  1. Audit Scope:
    • Will this replace existing logs (e.g., Laravel’s default logs/), or supplement them? Overlap may cause data duplication.
  2. Compliance Alignment:
    • Does the package’s schema meet regulatory requirements (e.g., GDPR’s "right to erasure")? Custom fields may need validation.
  3. Rollback Strategy:
    • How will audit logs be corrected if the package introduces bugs (e.g., missing events)?
  4. Testing Coverage:
    • Are there integration tests for the package’s event listeners? Unit tests alone may not catch DB race conditions.
  5. Alternatives:
    • Could spatie/laravel-activitylog alone suffice, or does this package add critical value (e.g., pre-built dashboards, export tools)?

Integration Approach

Stack Fit

  • Laravel 8+: Native support for events, service providers, and queue listeners ensures seamless integration.
  • PHP 8.0+: Leverages named arguments, attributes, and union types for cleaner event binding.
  • Database Layer: doctrine/dbal compatibility avoids ORM-specific quirks (e.g., Eloquent’s snake_case conventions).

Migration Path

  1. Phase 1: Pilot Deployment
    • Enable auditing for non-critical models (e.g., TestModel) to validate:
      • Event firing (e.g., created, updated).
      • Log consistency (e.g., no missing fields).
    • Use Laravel’s queue:work to test asynchronous logging under load.
  2. Phase 2: Core Integration
    • Extend spatie/laravel-activitylog config to include package-specific fields (e.g., ip_address, device_type).
    • Replace custom audit logic with package event listeners (e.g., AuditLogCreated).
  3. Phase 3: Full Rollout
    • Apply to high-value models (e.g., User, Order) with feature flags for gradual adoption.
    • Implement log archival (e.g., monthly exports to S3) to mitigate storage bloat.

Compatibility

  • Conflict Resolution:
    • If spatie/laravel-activitylog is already installed, composer will auto-resolve versions (check composer.json for ^4.7).
    • Service Provider Binding: Ensure the package’s AuditLogServiceProvider doesn’t clash with existing bindings (e.g., Activitylog).
  • Customization:
    • Override default log fields via config/auditing-log.php:
      'fields' => [
          'old' => true,
          'new' => true,
          'created_by' => auth()->id(),
      ],
      

Sequencing

  1. Pre-requisites:
    • Upgrade spatie/laravel-activitylog to v4.7+ if using an older version.
    • Ensure doctrine/dbal is installed (Laravel’s php artisan vendor:publish may handle this).
  2. Installation:
    composer require onramplab/laravel-auditing-log spatie/laravel-activitylog:^4.7
    php artisan vendor:publish --provider="OnrampLab\AuditLog\AuditLogServiceProvider"
    
  3. Configuration:
    • Publish and edit config/auditing-log.php to define loggable models and excluded events.
  4. Testing:
    • Write feature tests to verify:
      • Logs appear in audit_logs table.
      • Custom fields are populated (e.g., user_agent from middleware).

Operational Impact

Maintenance

  • Dependency Updates:
    • Monitor spatie/laravel-activitylog for breaking changes (e.g., schema migrations).
    • Pin onramplab/laravel-auditing-log to a specific version (e.g., 1.0.0) until stability is confirmed.
  • Schema Management:
    • The package creates a audit_logs table. Migrations must be version-controlled and tested in staging.
    • Plan for backward-compatible schema changes (e.g., adding nullable columns).

Support

  • Debugging:
    • Enable Laravel’s query logging (DB::enableQueryLog()) to diagnose slow audits.
    • Use telescope or laravel-debugbar to inspect event payloads.
  • Documentation Gaps:
    • The package lacks troubleshooting guides for common issues (e.g., "Logs not appearing"). Create internal runbooks for:
      • Event listener failures.
      • Database connection timeouts.

Scaling

  • Performance Bottlenecks:
    • Asynchronous Logging: Offload writes to a queue (e.g., audit-logged job) to avoid blocking user requests.
    • Batch Inserts: For high-volume systems, use DB::statement() to bulk-insert logs.
  • Storage Growth:
    • Implement log retention policies (e.g., soft-delete old logs via Activity::where('created_at', '<', now()->subYears(1))->delete()).
    • Consider read replicas for audit queries to reduce load on primary DB.

Failure Modes

Failure Scenario Impact Mitigation
Database connection drops Lost audit events Queue retries + dead-letter queue for failures.
Package event listener fails Incomplete logs Fallback to manual logging in finally blocks.
Schema migration fails Broken audit trails Rollback script + manual table repair.
High write load Slow responses Rate-limiting + queue batching.

Ramp-Up

  • Onboarding:
    • Developer Training:
      • Document how to annotate models for auditing (e.g., use \OnrampLab\AuditLog\Traits\AuditLoggable;).
      • Example:
        class Order extends Model {
            use AuditLoggable;
            protected $auditLogFields = ['status', 'amount'];
        }
        
    • QA Checklist:
      • Verify logs for create/update/delete events.
      • Test soft-deletes (if using spatie/laravel-activitylog’s soft-deletes).
  • Monitoring:
    • Track audit log volume (e.g., SELECT COUNT(*) FROM audit_logs).
    • Alert on failed events (e.g., failed_jobs table in Laravel).
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