gamma/api-logger-bundle
A lightweight logging bundle for APIs that captures requests, responses, and errors for easier debugging and monitoring. Helps trace issues across endpoints with minimal setup in Laravel/PHP applications.
Before anything else, understand what this package actually is: despite the api-logger name, gamma/api-logger-bundle is a Symfony-style bundle for the Gamma PHP framework (smart-gamma/gamma), not a Laravel package. There is no service provider, no config/api-logger.php, and no facade. A Laravel developer's realistic first step is to read the source as a reference implementation and port the logging/profile middleware pattern into Laravel's HTTP client and middleware stack.
If you are actually on a Gamma/Symfony app:
composer require gamma/api-logger-bundle — pin the exact version (2018-07-15 tag). Expect PHP 7.1/7.2-era constraints and Symfony 3.x/4.x transitive dependencies; Composer will likely block install on PHP 8+/Symfony 5+ without --ignore-platform-reqs.AppKernel::registerBundles) or the framework's bundle config file.config.yml / services.yml) and set the PSR-3 logger channel and log level — check the DependencyInjection/Configuration.php file in the repo for the exact keys, since there is no published docs.Where to look first, in order: README.md → DependencyInjection/Configuration.php (reveals all config keys) → the event subscriber / middleware class that does the actual logging → tests (if any) for expected log shape.
Decorator around the HTTP client. The safest pattern is to wrap your client in a decorator that logs before/after each call. If you're porting to Laravel, this is a natural fit for GuzzleHttp\HandlerStack middleware or a custom Illuminate\Http\Client macro:
$stack->push(Middleware::tap(
fn ($req) => $log->debug('api.request', ['method' => $req->getMethod(), 'uri' => (string) $req->getUri()]),
fn ($req, $res) => $log->info('api.response', ['status' => $res->getStatusCode(), 'ms' => ...])
));
Correlation IDs. Generate a request ID per inbound Laravel request (middleware) and inject it into every outbound log context. The bundle's older logging likely predates this convention, so add it yourself — it's the highest-value change.
Profiling as timing spans. The "profiling" half is usually just microtime(true) deltas around the request. Record them as structured fields (duration_ms, bytes, status) rather than free-text, so they're queryable in Loki/ELK/Datadog.
Channel separation. Log API traffic to a dedicated channel with its own retention and level. In Laravel: a api channel in config/logging.php. Do not pour request bodies into laravel.log.
Sampling and failure-only modes. Daily traffic will drown you. Log all 4xx/5xx at warning, sample successful 2xx (e.g. 1 % or 10 %), and always log 5xx. The bundle itself has no sampling toggle — build it in the decorator.
Integration with testing. In tests, bind a NullLogger (or a TestLogger that asserts context) so the decorator doesn't spam output. Assert the shape of the context array, not the message string.
config/app.php provider entry, no artisan command, no Blade of config help. The concepts port cleanly; the code does not.LoggerInterface. composer install on PHP 8.2+ will fail platform checks; --ignore-platform-reqs will get you past it but leave you debugging TypeErrors from older signatures.Authorization, Cookie, Set-Cookie, and any *_token keys before the context hits the logger. The bundle will not do this for you.debug line in the subscriber's __construct to confirm it's instantiated. bin/console debug:container is your friend on Symfony; php artisan about / container dumps on a port.microtime(true) calls is fine; timestamps from database clocks or NTP-skewed hosts are not. Use a monotonic-enough clock consistently in one place.README on GitHub is the only documentation — read the source, not the prose.Guzzle middleware + a dedicated api log channel gives you 95 % of what this bundle offers, with modern PHP support and no 2018 baggage.How can I help you explore Laravel packages today?