我的API(Laravel APP)已部署在AWS Lambda上。 目标是将每个请求/响应对记录到Cloudwatch。
我的方法是:
-在config/logging.php
内定义Cloudwatch频道,如下所示:
'cloudwatch' => [
'name' => env('CLOUDWATCH_LOG_NAME', ''),
'region' => env('CLOUDWATCH_LOG_REGION', ''),
'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', 14),
'group_name' => env('CLOUDWATCH_LOG_GROUP_NAME', 'laravel_app'),
'version' => env('CLOUDWATCH_LOG_VERSION', 'latest'),
'formatter' => \Monolog\Formatter\JsonFormatter::class,
'disabled' => env('DISABLE_CLOUDWATCH_LOG', false),
],
然后创建一个API中间件,然后使用以下命令将值记录到该通道:
Log::channel('cloudwatch')->info('Something happened!');
此更改不会引起任何问题,但是在AWS CloudWatch中看不到任何日志。
任何想法我想念的东西在哪里?