-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Laravel 8 to 10 upgrade cloudwatch error #43
Comments
@dekts Have you found a fix for this? |
Actual issue - maxbanton/cwh#116 Looks like this project has been abandoned |
As a workaround, until this package depends on maxbanton/cwh, it's possible to use this fork (phpnexus/cwh), instantiating the handler through service container - keeping the same config structure. Remove pagevamp/laravel-cloudwatch-logs and install phpnexus/cwh. Providers/AppServiceProvider.php
config/logging.php
|
I no longer use this package, so have not really tested this. |
The open PR solves it |
@developernaren can I ask what are you using instead? |
@hungnv-sr I no longer use PHP in my job. I still love PHP though. Also, I have released a new version v1.1.0 . |
I've upgraded but I'm getting the following error hitting my logs in Laravel... laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (Error(code: 0): Class "Phpnexus\Cwh\Handler\CloudWatch" not found at /var/www/vendor/pagevamp/laravel-cloudwatch-logs/src/Logger.php:34) Have I missed something somewhere? |
@jmsutton1981 it was my bad when creating pull request. @developernaren I'm sorry, can you merge that again? |
@hungnv-sr has sent a PR to fix the typo in the name of the imported package. I have merged and created a new version. v1.1.1 |
Updated and this has fixed the issue, thanks everyone |
closing this as looks like this is fixed! |
I think there still might be something going on here. We pushed updates to all of our deployments yesterday and all of a sudden cloudwatch logging quit working. No errors, nothing amiss on the frontend, just logs stopped showing up in CW. I went looking and found this ticket, then did a composer update... I pulled the latest version of this dependency 1.1.1, and verified the fixes outlined here are in my vendor dir... I also tried the workaround written above and still no logs. Any help would be greatly appreciated on this as we've got some production clients running on this. |
Yes, I built custom PHP file to log using phpnexus/cwh Install first this Then I have added one file inside the This is the code of <?php
namespace App\Logging;
use Aws\CloudWatchLogs\CloudWatchLogsClient;
use PhpNexus\Cwh\Handler\CloudWatch;
use Monolog\Logger;
use Monolog\Level;
use Monolog\Formatter\JsonFormatter;
class CloudWatchLoggerFactory
{
/**
* Create a custom Monolog instance.
*
* @param array $config
* @return \Monolog\Logger
*/
public function __invoke(array $config)
{
$sdkParams = $config["sdk"];
$tags = $config["tags"] ?? [];
$name = $config["name"] ?? 'cloudwatch';
// Instantiate AWS SDK CloudWatch Logs Client
$client = new CloudWatchLogsClient($sdkParams);
// Log group name, will be created if none
$groupName = $config["group_name"];
// Log stream name, will be created if none
$streamName = $config["stream_name"];
// Days to keep logs, 14 by default. Set to `null` to allow indefinite retention.
$retentionDays = $config["retention"];
$batchSize = $config["batch_size"];
// Instantiate handler (tags are optional)
$handler = new CloudWatch($client, $groupName, $streamName, $retentionDays, $batchSize, $tags);
// Optionally set the JsonFormatter to be able to access your log messages in a structured way
$handler->setFormatter(new JsonFormatter());
// Create a log channel
$logger = new Logger($name);
// Set handler
$logger->pushHandler($handler);
return $logger;
}
} Then change the 'cloudwatch' => [
'driver' => 'custom',
'name' => env('CLOUDWATCH_LOG_NAME', ''),
'sdk' => [
'region' => env('CLOUDWATCH_LOG_REGION', 'us-east-1'),
'version' => 'latest',
'credentials' => [
'key' => env('CLOUDWATCH_LOG_KEY'),
'secret' => env('CLOUDWATCH_LOG_SECRET')
]
],
'stream_name' => env('CLOUDWATCH_LOG_STREAM_NAME', 'laravel_app'),
'retention' => env('CLOUDWATCH_LOG_RETENTION_DAYS', 7),
'group_name' => env('CLOUDWATCH_LOG_GROUP_NAME', 'laravel_app'),
'version' => env('CLOUDWATCH_LOG_VERSION', 'latest'),
'formatter' => \Monolog\Formatter\JsonFormatter::class,
'batch_size' => env('CLOUDWATCH_LOG_BATCH_SIZE', 10000),
'level' => env('CLOUDWATCH_LOG_LEVEL', 'debug'),
'via' => \App\Logging\CloudWatchLoggerFactory::class,
], Here we just need to change via attribute value. from Cheers! |
Declaration of Maxbanton\Cwh\Handler\CloudWatch::write(array $record): void must be compatible with Monolog\Handler\AbstractProcessingHandler::write(Monolog\LogRecord $record): void
The text was updated successfully, but these errors were encountered: