php - 无法使用 PHP 登录 AWS Cloudwatch?
问题描述
我正在使用 PHP 通过 cloudwatch 记录某些内容,我的应用程序部署在 AWS Elastic Beanstalk 上。我遵循了 AWS Dev Doc,我尝试实现那里定义的所有内容,但我仍然没有在 cloudwatch 上记录任何内容,也没有在 beanstalk 日志上记录任何内容。日志文件正在我的本地系统中创建,其中包含所有日志,那里有什么问题?有人请帮助我。
文档 -链接
代码 -
<?php
use Aws\CloudWatchLogs\CloudWatchLogsClient;
use Maxbanton\Cwh\Handler\CloudWatch;
use Monolog\Logger;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogHandler;
$logFile = "testapp_local.log";
$appName = "TestApp01";
$facility = "local0";
$awsCredentials = [
'region' => 'eu-east-2',
'version' => 'latest',
'credentials' => [
'key' => 'KEY',
'secret' => 'Secret KEY'
]
];
$cwClient = new CloudWatchLogsClient($awsCredentials);
// Log group name, will be created if none
$cwGroupName = 'php-applog-test#--1';
// Log stream name, will be created if none
$cwStreamNameInstance = 'some-stream-name-EC2-instance-1';
// Instance ID as log stream name
$cwStreamNameApp = "TestAuthenticationApp";
// Days to keep logs, 14 by default
$cwRetentionDays = 90;
$cwHandlerInstanceNotice = new CloudWatch($cwClient, $cwGroupName, $cwStreamNameInstance, $cwRetentionDays, 10000, [ 'application' => 'DemoFormTwo' ],Logger::NOTICE);
$cwHandlerInstanceError = new CloudWatch($cwClient, $cwGroupName, $cwStreamNameInstance, $cwRetentionDays, 10000, [ 'application' => 'DemoFormTwo' ],Logger::ERROR);
$cwHandlerAppNotice = new CloudWatch($cwClient, $cwGroupName, $cwStreamNameApp, $cwRetentionDays, 10000, [ 'application' => 'DemoFormTwo' ],Logger::NOTICE);
$logger = new Logger('PHP Logging');
$formatter = new LineFormatter(null, null, false, true);
$syslogFormatter = new LineFormatter("%channel%: %level_name%: %message% %context% %extra%",null,false,true);
$infoHandler = new StreamHandler(__DIR__."/".$logFile, Logger::INFO);
$infoHandler->setFormatter($formatter);
$warnHandler = new SyslogHandler($appName, $facility, Logger::WARNING);
$warnHandler->setFormatter($syslogFormatter);
$cwHandlerInstanceNotice->setFormatter($formatter);
$cwHandlerInstanceError->setFormatter($formatter);
$cwHandlerAppNotice->setFormatter($formatter);
$logger->pushHandler($warnHandler);
$logger->pushHandler($infoHandler);
$logger->pushHandler($cwHandlerInstanceNotice);
$logger->pushHandler($cwHandlerInstanceError);
$logger->pushHandler($cwHandlerAppNotice);
$logger->info('Initial test of application logging.');
$logger->warn('Test of the warning system logging.');
$logger->notice('Application Auth Event: ',[ 'function'=>'login-action','result'=>'login-success' ]);
$logger->notice('Application Auth Event: ',[ 'function'=>'login-action','result'=>'login-failure' ]);
$logger->error('Application ERROR: System Error');
?>
我已经安装
curl -sS https://getcomposer.org/installer | php
php composer.phar require aws/aws-sdk-php
php composer.phar require monolog/monolog
php composer.phar require maxbanton/cwh:^1.0
这些依赖于beantalk。我正在使用文档示例中给出的独白(作曲家)。这里的问题是日志只在我的本地系统中生成,而不是在 Cloudwatch 中我怎样才能让它们出现在 CW 上?
解决方案
推荐阅读
- google-cloud-platform - 谷歌云支付方式 API
- php - 作曲家 - 您的要求无法解决为一组可安装的软件包
- ios - 我无法从另一个 ViewController 执行功能
- java - 使用 Java 上传表单数据中的文件
- python - 使用 tfidvectoriser 时出现奇怪的线条,可能是用 ' ' 替换引起的?
- mode - 如何制作夜间模式?
- java - 单元测试不能通过
- javascript - 尽快:恶意软件清除 javascript
- javascript - 在 POST 到服务器之前将捕获的 getUserMedia 视频保存到文件
- python - 如何修复'NameError:名称'russ_yaz'未定义'