adityasetiono/api-logger-bundle
Symfony2 bundle that logs REST API requests/responses (default /api/), tracks duration, and flags slow calls. Configurable enable/disable and slow-time threshold, with optional separate Monolog channels/files for API and slow logs.
HttpFoundation), which Laravel also leverages. Core logging/profiling logic can be extracted and ported.EventDispatcher, HttpKernel, and Monolog. Laravel has equivalents (Illuminate\Events, Illuminate\Http, Monolog), but direct integration would require abstraction.Log facade).Request, Response) may need refactoring for Laravel’s Illuminate\Http\Request.Is the logging granularity sufficient?
Performance Impact:
Laravel-Specific Gaps:
HandleIncomingRequest)?single, daily, slack)?Maintenance Burden:
Log + custom middleware) with lower risk?LogApiRequests middleware to wrap handle() with profiling/logging.LoggerService to handle formatting/storage (e.g., JSON logs to storage/logs/api.log).HttpFoundation\Request → Illuminate\Http\RequestMonolog → Laravel’s Log facadeEventDispatcher → Laravel’s Events system (if using event-based logging).Phase 1: Proof of Concept
laravel-debugbar, monolog).Phase 2: Middleware Integration
app/Http/Middleware/ApiLogger.php).$middleware array in app/Http/Kernel.php for global use..env (e.g., API_LOGGER_SLOW_THRESHOLD=1000).Phase 3: Feature Parity
ContainerAware).Log::channel('daily')).| Step | Task | Dependencies |
|---|---|---|
| 1 | Fork/clone the bundle | Git access |
| 2 | Replace Symfony components with Laravel equivalents | Laravel core |
| 3 | Test basic logging in a Laravel route | PHPUnit |
| 4 | Build middleware wrapper | Laravel middleware |
| 5 | Add configuration via .env |
Laravel config |
| 6 | Implement slow-call detection | Laravel events/queues |
| 7 | Benchmark performance impact | Load testing (e.g., Artisan CLI) |
| 8 | Deploy to staging | CI/CD pipeline |
Illuminate\Http).Benchmark facade).Log::useQueue()).memory_get_usage().Log::useDailyFiles()).| Risk | Mitigation |
|---|---|
| Logging fails silently | Add retry logic or circuit breaker for log writes. |
| Profiling skews performance | Exclude health checks or use sampling. |
| Log files become unreadable | Enforce JSON/structured logging format. |
| Bundle breaks on Laravel updates | Isolate dependencies (e.g., pin monolog/monolog version). |
| Slow-call alerts flood | Add rate-limiting to alert triggers. |
composer require alternatives)..env variables).How can I help you explore Laravel packages today?