cwh
cwh copied to clipboard
Incompatibility with Monolog 3
Describe the bug Support for Monolog v3 has been added in the composer file in v2.0.3: https://github.com/maxbanton/cwh/pull/106
However it seems like the methods are not compatible with the Monolog v3 interfaces:
Fatal error: Declaration of Maxbanton\Cwh\Handler\CloudWatch::write(array $record): void must be compatible with Monolog\Handler\AbstractProcessingHandler::write(Monolog\LogRecord $record): void in .../vendor/maxbanton/cwh/src/Handler/CloudWatch.php on line 164
Please tell about your environment:
- PHP Version: 8.1.12
- Operating system (distro): debian
- Application mode:
- [X] Web app
- [ ] CLI app
- [ ] Daemon worker
see https://github.com/Seldaek/monolog/blob/main/UPGRADE.md#300
Hi @guillaumesmo.
I'm working on support of Monolog V3, could you please test cwh package from branch feature/php-8.1
?
Something like this
composer require maxbanton/cwh:feature/php-8.1
@maxbanton, branch feature/php-8.1 seems to work fine with Monolog 3, except one small issue (might be on my side only):
Symfony throws an error when autowiring the CloudWatch class:
Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\RuntimeException: Unable to dump a service container if a parameter is an object or a resource
after some investigation it seems like this is due to the $level
argument which is now an enum, and either it doesn't seem to be supported by Symfony autowiring, or it's a bug.
workaround is to set the $level
argument in the service definition
autowire: true
class: Maxbanton\Cwh\Handler\CloudWatch
arguments:
$level: 100
$level: !php/enum Monolog\Level::Debug # as of Symfony 6.2
However, I created this issue not because Monolog 3 is not yet supported, but because it has been (mistakenly?) added in the composer of maxbanton/cwh v2.0.3, so that version is actually broken if you don't hardcode Monolog v2 in your composer.json
https://github.com/maxbanton/cwh/issues/108#issuecomment-1308694154 wow, yeah that seems to have been caused by me through https://github.com/maxbanton/cwh/pull/106 😨 , sorry guys!
would be great to see this resolved if possible, i see theres an open pr for php8.1 + monolog v3, is there anything that needs to be done to get it over the line that i can help with ?
@maxbanton thanks for the package! Any plans to release the feature/php-8.1 in the near future?
@maxbanton any Monolog 3 updates? This is blocking my migration to Laravel 10.
an alternative to using this monolog handler is to setup the aws cloudwatch agent on your deployments that records the standard laravel.log output
@mad-briller thanks, but that's not a good option for me. I'm running Dockerised Laravel in ECS - it's designed around having one process running so running a Cloudwatch agent alongside the web server under some kind of supervisor process adds complexity and is a bit of an antipattern.
I switched to the fork phpnexus/cwh. Worked a treat!