codemonauts/yii2-cloudwatch-logs
Composer 安装命令:
composer require codemonauts/yii2-cloudwatch-logs
包简介
A Yii 2 log target for AWS Cloudwatch Logs
关键字:
README 文档
README
A Yii2 log target for AWS Cloudwatch Logs.
Installation and Configuration
Install the package through composer:
composer require codemonauts/yii2-cloudwatch-logs
And then add this to your application configuration:
<?php return [ // ... 'components' => [ // ... 'log' => [ 'targets' => [ [ 'class' => \codemonauts\cloudwatchlogs\Target::class, 'region' => 'eu-west-1', 'logGroup' => '/webserver/production/my-craft', 'logStream' => 'instance-1', // omit for automatic instance ID 'levels' => ['error', 'warning', 'info', 'trace', 'profile'], 'logVars' => ['_GET', '_POST', '_FILES', '_COOKIE', '_SESSION', '_SERVER'], 'key' => 'your-key', // omit for instance role 'secret' => 'your-secret', // omit for instance role ], // ... ], ],
Configuration Options
- (string)
$region(required) The name of the AWS region e.g. eu-west-1 - (string)
$logGroup(required) The name of the log group. - (string)
$logStream(optional) The name of the log stream. If omitted, it will try to determine the ID of the EC2 instance running on. - (array)
$levels(optional) Log level. Default by Yii2: ['error', 'warning', 'info', 'trace', 'profile'] - (array)
$logVars(optional) Variables to log. Default by Yii2: ['_GET', '_POST', '_FILES', '_COOKIE', '_SESSION', '_SERVER'] - (string)
$key(optional) Your AWS access key. - (string)
$secret(optional) Your AWS secret.
Rate limit
The Cloudwatch Logs API requires a sequence token to be send with the messages to a log stream. This token is returned after a transfer of messages to the log stream to be used at the next transfer. For multi-process systems this is hard to handle.
So AWS Cloudwatch Logs does not support multiple processes writing to the same log stream at the same time. Their official approach is to create a separate log stream for each process on each instance. But think of PHP-FPM with dynamic childs on several instances. This would end up in thousands of abandoned log streams in a log group after a while. Empty log streams are not deleted automatically and remain in the log groups. They do not cost anything, but make log groups very messy.
Our approach is to create only one log stream per instance. To be able to send log streams from multiple processes at the same time, the current sequence token of the log stream must be queried before each transmission. But the AWS Cloudwatch Log API has a rate limit of 60 requests per second for this type of request.
In order to avoid running into this rate limit, it is highly advisable to pass only those logs directly to Cloudwatch Logs that happen rarely and are important. For example Warnings and Errors.
In large infrastructures with many simultaneous processes with a high log load, it is still better to use file logging and the Cloudwatch Log Agent, as this is only a single process.
Maybe this will change in the future.
Cloudwatch Logs Insights
If you want to parse the logs with Insights, then do something like this:
fields @timestamp, @message
| sort @timestamp desc
| limit 20
| parse '[*][*][*][*][*] *' as ip, userId, sessionId, logLevel, category, message
codemonauts/yii2-cloudwatch-logs 适用场景与选型建议
codemonauts/yii2-cloudwatch-logs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 60.4k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2019 年 03 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「aws」 「yii2」 「cloudwatch」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 codemonauts/yii2-cloudwatch-logs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 codemonauts/yii2-cloudwatch-logs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 codemonauts/yii2-cloudwatch-logs 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
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
simple api library.
A replica of the AWS Elastic Beanstalk worker SQS daemon (sqsd) in PHP
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
统计信息
- 总下载量: 60.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-03-08