cwh icon indicating copy to clipboard operation
cwh copied to clipboard

Incompatibility with Monolog 3

Open guillaumesmo opened this issue 2 years ago • 10 comments

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

guillaumesmo avatar Nov 07 '22 13:11 guillaumesmo

see https://github.com/Seldaek/monolog/blob/main/UPGRADE.md#300

guillaumesmo avatar Nov 07 '22 13:11 guillaumesmo

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 avatar Nov 07 '22 15:11 maxbanton

@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

guillaumesmo avatar Nov 09 '22 12:11 guillaumesmo

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!

holtkamp avatar Nov 09 '22 16:11 holtkamp

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 ?

mad-briller avatar Feb 24 '23 13:02 mad-briller

@maxbanton thanks for the package! Any plans to release the feature/php-8.1 in the near future?

aglipanci avatar Feb 28 '23 15:02 aglipanci

@maxbanton any Monolog 3 updates? This is blocking my migration to Laravel 10.

ravewill avatar Aug 07 '23 01:08 ravewill

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 avatar Aug 07 '23 11:08 mad-briller

@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.

ravewill avatar Aug 07 '23 22:08 ravewill

I switched to the fork phpnexus/cwh. Worked a treat!

ravewill avatar Aug 08 '23 04:08 ravewill