Download the PHP package maxbanton/cwh without Composer
On this page you can find all versions of the php package maxbanton/cwh. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download maxbanton/cwh
More information about maxbanton/cwh
Files in maxbanton/cwh
Package cwh
Short Description AWS CloudWatch Handler for Monolog library
License MIT
Homepage https://github.com/maxbanton/cwh
Informations about the package cwh
AWS CloudWatch Logs Handler for Monolog
Handler for PHP logging library Monolog for sending log entries to AWS CloudWatch Logs service.
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
Logs are shipped to AWS CloudWatch Logs synchronously inside your PHP process. For very high-throughput workloads (thousands of records/sec sustained per process), consider an out-of-process pipeline — for example, logging to stdout and forwarding with the CloudWatch agent — that decouples log shipping from request latency and isolates AWS API failures from your app. For typical web and worker workloads, this handler is fine.
Requirements
- PHP ^8.1
- Monolog ^3.0
- AWS account with proper permissions (see list of permissions below)
Features
- Batches up to 10,000 events per
PutLogEventscall (the AWS per-batch maximum), with automatic flush on size (1 MB), event-timespan (24 h), or buffer-full thresholds - Splits oversized records (> 1 MB) into multiple events automatically
- Optional log-group creation with tags and retention policy
- Lazy log-group / log-stream initialization on first write
- Public
flush()andreset()for long-lived workers (Symfony Messenger, Laravel queues / Octane, custom daemons) - Suitable for web applications and for long-running CLI daemons and workers
Installation
Install the latest version with Composer by running
Basic Usage
Using IAM Task Roles on ECS / EC2
When running on ECS or EC2, prefer the task/instance IAM role over hard-coded credentials. Wrap the credential provider in memoize() so long-running workers don't hit metadata-endpoint timeouts:
Frameworks integration
Migrating from 2.x to 3.x
3.x is a breaking release that drops Monolog 2 and PHP 7.x support. The constructor parameter order, names, and defaults are preserved — existing Symfony YAML and Laravel with/handler_with configs continue to work after the platform upgrades below.
Required changes:
- Bump PHP to 8.1 or newer.
- Bump Monolog to 3.x.
- The
Monolog\Logger::DEBUG(and other) constants were removed in Monolog 3. UseMonolog\Level::Debuginstead —int|string|Levelare all accepted by the$levelconstructor argument. - Symfony service definitions referencing
!php/const Monolog\Logger::WARNINGmust change to!php/const Monolog\Level::Warning. - Laravel channels using
'level' => 'warning'(string form) keep working unchanged. - Subclasses overriding
protected function write(array $record): voidmust update the signature toprotected function write(\Monolog\LogRecord $record): voidand access fields via$record->propertyinstead of$record['key'].
New (optional):
- A 10th constructor argument
$createStream(defaulttrue). Set tofalseto skipDescribeLogStreams/CreateLogStreamfor pre-provisioned streams; lets you drop those IAM permissions.
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.
When setting the $createStream argument to false, permissions DescribeLogStreams and CreateLogStream can be omitted. Use this when the log stream is provisioned out of band (e.g. via Terraform). If the stream does not exist at runtime, PutLogEvents will fail with ResourceNotFoundException.
AWS IAM Policy full json example
Issues
Feel free to report any issues
Contributing
Please check this document
Made in Ukraine 🇺🇦