kirubha7/cloudwatch-logs-laravel
Composer 安装命令:
composer require kirubha7/cloudwatch-logs-laravel
包简介
Laravel Cloudwatch Logs Package
关键字:
README 文档
README
Before using this library, it's recommended to get acquainted with the pricing for AWS CloudWatch services.
Please press ★ Star button if you find this library useful.
Disclaimer
This library uses AWS API through AWS PHP SDK, which has limits on concurrent requests. It means that on high concurrent or high load applications it may not work on it's best way. Please consider using another solution such as logging to the stdout and redirecting logs with fluentd.
Requirements
- PHP ^7.2
- aws/aws-sdk-php": "^3.18
- AWS account with proper permissions (see list of permissions below)
Features
- Creating Log Groups
- Creating Log Streams
- Check if Log Groups exists or not
- Check if Log Stream exists or not
- Sending Logs to cloudwatch log stream
- AWS CloudWatch Logs staff lazy loading
- Suitable for web applications and for long-living CLI daemons and workers
Installation
Install the latest version with Composer by running
$ composer require kirubha7/cloudwatch-logs-laravel
Basic Usage
<?php use kirubha7\CloudwatchLogsLaravel\Cloudwatchlogs; use Aws\CloudWatchLogs\CloudWatchLogsClient; $client = [ 'region' => 'AWS_REGION', 'version' => '2014-03-28', 'credentials' => [ 'key' => 'AWS_KEY', 'secret' => 'AWS_SECRET', ] ]; $client = new CloudWatchLogsClient($client);//Intialize AWS Clinet $logs = new Cloudwatchlogs($client); try{ //YOUR CONTEXT $datas = [ 'test' => 'package', 'version' => 1, ]; $retentionDays = 30;//By Default retention days upto 14 days /** Generally putLog function returns associate array If Logs sends successfully => ['status' => true,'message' => 'Log sended successfully'] If Logs failed to sends => ['status' => false,'error' => 'EXCEPTION_MESSAGE'] */ $res = $logs->putLog('YOUR_LOGGROUP_NAME','YOUR_LOGSTREAM_NAME',$retentionDays,$datas); if($res['status']){//If log sends successfully echo $res['message']; }else{//If log fails to sends echo $res['error']; } }catch(\Exception $e){ echo $e->getMessage(); }
To check if Log Group exists
<?php /** Generally checkLogGroupExists function returns associate array If Logs group exists => ['status' => true,'message' => 'Log Group Exists'] If Logs group not exists => ['status' => false,'error' => 'EXCEPTION_MESSAGE'] */ $res = $logs->checkLogGroupExists('YOUR_LOG_GROUP_NAME'); if($res['status']){//If log group is exists echo $res['message']; }else{//If log group not exists echo $res['error']; } ?>
To check if Log Stream exists
<?php /** Generally checkLogStreamExists function returns associate array If Logs stream exists => ['status' => true,'message' => 'Log Stream Exists'] If Logs stream not exists => ['status' => false,'error' => 'EXCEPTION_MESSAGE'] */ $res = $logs->checkLogStreamExists('YOUR_LOG_STREAM_NAME'); if($res['status']){//If log stream is exists echo $res['message']; }else{//If log stream not exists echo $res['error']; } ?>
To create log group
<?php /** Generally createLogGroup function returns associate array If Logs group created successfully => ['status' => true,'message' => 'Log Group Created Successfully'] If Logs group fails to create => ['status' => false,'error' => 'EXCEPTION_MESSAGE'] */ $res = $logs->createLogGroup('YOUR_LOG_GROUP_NAME'); if($res['status']){//If log group created successfully echo $res['message']; }else{//If log group fails to create echo $res['error']; } ?>
To craete log stream
<?php /** Generally createLogStream function returns associate array If Logs stream created successfully => ['status' => true,'message' => 'Log Stream Created Successfully'] If Logs stream fails to create => ['status' => false,'error' => 'EXCEPTION_MESSAGE'] */ $res = $logs->createLogStream('YOUR_LOG_GROUP_NAME','YOUR_LOG_STREAM_NAME'); if($res['status']){//If log stream created successfully echo $res['message']; }else{//If log stream fails to create echo $res['error']; } ?>
AWS IAM needed permissions
if you prefer to use a separate programmatic IAM user (recommended) or want to define a policy, make sure following permissions are included:
CreateLogGroupaws docsCreateLogStreamaws docsPutLogEventsaws docsPutRetentionPolicyaws docsDescribeLogStreamsaws docsDescribeLogGroupsaws docs
When setting the $createGroup argument to false, permissions DescribeLogGroups and CreateLogGroup can be omitted
AWS IAM Policy full json example
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:DescribeLogGroups"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:DescribeLogStreams",
"logs:PutRetentionPolicy"
],
"Resource": "{LOG_GROUP_ARN}"
},
{
"Effect": "Allow",
"Action": [
"logs:PutLogEvents"
],
"Resource": [
"{LOG_STREAM_1_ARN}",
"{LOG_STREAM_2_ARN}"
]
}
]
}
Issues
Feel free to report any issues
Made in India
kirubha7/cloudwatch-logs-laravel 适用场景与选型建议
kirubha7/cloudwatch-logs-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.23k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 09 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「monolog」 「aws」 「cloudwatch」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kirubha7/cloudwatch-logs-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kirubha7/cloudwatch-logs-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kirubha7/cloudwatch-logs-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A GeoIP decorator/processor for monolog
This package includes a script and fail2ban configuration that allows you to use fail2ban when utilizing AWS elastic load balancer (ELB) and an apache webserver.
Elastic Driver for Laravel Scout
Log events to AWS CloudWatch including embedded metrics
A Zend Framework module that sets up Monolog for logging in applications.
Laravel 5.6 Monolog custom telegram channel
统计信息
- 总下载量: 5.23k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-10