PHPackages                             sinemacula/laravel-log-cloudwatch - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. sinemacula/laravel-log-cloudwatch

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

sinemacula/laravel-log-cloudwatch
=================================

A CloudWatch Monolog log driver for Laravel.

00PHPCI passing

Since Jun 26Pushed todayCompare

[ Source](https://github.com/sinemacula/laravel-log-cloudwatch)[ Packagist](https://packagist.org/packages/sinemacula/laravel-log-cloudwatch)[ RSS](/packages/sinemacula-laravel-log-cloudwatch/feed)WikiDiscussions master Synced today

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Laravel Log CloudWatch
======================

[](#laravel-log-cloudwatch)

[![Latest Stable Version](https://camo.githubusercontent.com/16554a691b68ff1085bdf39d303ca452922ee3da63a59e5b4f7f2239f53b2957/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73696e656d6163756c612f6c61726176656c2d6c6f672d636c6f756477617463682e737667)](https://packagist.org/packages/sinemacula/laravel-log-cloudwatch)[![Build Status](https://github.com/sinemacula/laravel-log-cloudwatch/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/sinemacula/laravel-log-cloudwatch/actions/workflows/tests.yml)[![Quality Gates](https://github.com/sinemacula/laravel-log-cloudwatch/actions/workflows/quality-gates.yml/badge.svg?branch=master)](https://github.com/sinemacula/laravel-log-cloudwatch/actions/workflows/quality-gates.yml)[![Maintainability](https://camo.githubusercontent.com/b51950d03f9ee3d1e2d04de95dbb1e6ea4716e3fad1f43a2a6f0275b4c94cd20/68747470733a2f2f716c74792e73682f67682f73696e656d6163756c612f70726f6a656374732f6c61726176656c2d6c6f672d636c6f756477617463682f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/sinemacula/projects/laravel-log-cloudwatch)[![Code Coverage](https://camo.githubusercontent.com/c4750e14186be0bc5ff662a2a910796ff5dcd5f7df95dd64208799e11fa8682c/68747470733a2f2f716c74792e73682f67682f73696e656d6163756c612f70726f6a656374732f6c61726176656c2d6c6f672d636c6f756477617463682f636f7665726167652e737667)](https://qlty.sh/gh/sinemacula/projects/laravel-log-cloudwatch)[![Total Downloads](https://camo.githubusercontent.com/89ce0c93dc272438ef03621d12aca340d9256b681593827bddb8fde5970ba1cf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73696e656d6163756c612f6c61726176656c2d6c6f672d636c6f756477617463682e737667)](https://packagist.org/packages/sinemacula/laravel-log-cloudwatch)

A CloudWatch Monolog log driver for Laravel. Registers a `cloudwatch` custom log channel that ships log records to AWS CloudWatch Logs via [phpnexus/cwh](https://github.com/phpnexus/cwh), so application logs land in CloudWatch without any bespoke wiring.

The driver is registered automatically through Laravel's package auto-discovery; add a `cloudwatch` channel to your logging config (see below) to start shipping logs.

How It Works
------------

[](#how-it-works)

The package registers a `cloudwatch` driver with Laravel's log manager through `LogCloudWatchServiceProvider`. When a channel configured with `'driver' => 'cloudwatch'` is resolved, the driver builds a Monolog `Logger` backed by a single [phpnexus/cwh](https://github.com/phpnexus/cwh) CloudWatch handler, constructed from the channel's settings.

A few rules hold:

- **Standard Laravel logging.** Once configured, the channel behaves like any other Laravel log channel: use it directly, inside a `stack`, or as the default `LOG_CHANNEL`.
- **Batched delivery.** Records are buffered and flushed in batches (`batch_size`) to keep CloudWatch API calls efficient, and the log group's retention is set from `retention`.

Installation
------------

[](#installation)

```
composer require sinemacula/laravel-log-cloudwatch
```

The service provider is auto-discovered.

Configuration
-------------

[](#configuration)

Add a `cloudwatch` channel to your `config/logging.php`:

```
'cloudwatch' => [
    'driver'     => 'cloudwatch',
    'aws'        => [
        'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
    ],
    'log_group'  => env('CLOUDWATCH_LOG_GROUP', '/app/laravel'),
    'log_stream' => env('CLOUDWATCH_LOG_STREAM', 'application'),
    'retention'  => env('CLOUDWATCH_LOG_RETENTION', 7),
    'batch_size' => env('CLOUDWATCH_LOG_BATCH_SIZE', 1000),
    'level'      => env('LOG_LEVEL', 'debug'),
],
```

This example relies on the AWS default credential provider chain (an IAM role or instance profile), which is the recommended setup. To supply static credentials instead, see [Credentials](#credentials).

KeyDescriptionDefault`driver`Must be `cloudwatch` to resolve this driver.-`name`Monolog channel name used in formatted output.`cloudwatch``aws.region`AWS region for the CloudWatch Logs client. **Required.**-`aws.credentials`Static credentials. Supply both `key` and `secret`, or neither (uses the default provider chain). See below.-`log_group`The CloudWatch log group log records are written to. **Required.**-`log_stream`The log stream within the group. **Required.**-`retention`Days to retain log events; `null` leaves the existing policy untouched. Applied only when the group is made.`7``batch_size`Number of records buffered before a flush to CloudWatch (max `10000`).`1000``level`Minimum Monolog level the handler will record.`debug``create_group`Whether to create the log group if it does not exist.`true``create_stream`Whether to create the log stream if it does not exist.`true``tags`Tags applied to the log group when it is created.`[]``rps_limit`Requests-per-second limit before a one-second sleep is triggered; `0` disables.`0``bubble`Whether records bubble to lower-priority handlers in a `stack`.`true``cache`A PSR-6 `Psr\Cache\CacheItemPoolInterface` instance or class string to cache group/stream existence (below).-`cache_ttl`TTL in seconds for cached group/stream existence checks.`300``formatter`A `Monolog\Formatter\FormatterInterface` instance or class string.handler default`processors`Monolog processors (callables or class strings) added to the channel.`[]``tap`Classes that receive the channel to customise it (applied by Laravel).`[]`### Credentials

[](#credentials)

Prefer the AWS default credential provider chain - IAM roles, instance profiles, ECS task roles, or environment variables - which the example above uses by omitting `aws.credentials` entirely. This keeps long-lived secrets out of your application config and is the recommended production setup.

To supply static credentials instead, add an `aws.credentials` block with **both** a `key` and a `secret` (supplying only one is rejected):

```
'aws' => [
    'region'      => env('AWS_DEFAULT_REGION', 'us-east-1'),
    'credentials' => [
        'key'    => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
    ],
],
```

Static credentials live in the channel config array, which can surface in stack traces captured by error trackers. Set `zend.exception_ignore_args=1` in your production `php.ini` to keep argument values out of traces, or prefer the default provider chain above.

### Least-privilege deployments

[](#least-privilege-deployments)

When the log group is provisioned out of band (Terraform, CDK) and the application's IAM role is scoped to only `logs:PutLogEvents` / `logs:CreateLogStream`, disable group creation and retention management so the handler does not attempt calls it is not permitted to make:

```
'create_group'  => false,
'create_stream' => false,
'retention'     => null,
```

### Structured logging

[](#structured-logging)

Set a `formatter` to ship structured records - JSON works well with CloudWatch Logs Insights:

```
'formatter' => Monolog\Formatter\JsonFormatter::class,
```

### Caching group/stream existence

[](#caching-groupstream-existence)

Under PHP-FPM, each request re-checks (and creates, if enabled) the log group and stream on its first write. Supply a PSR-6 cache pool to share those existence checks across requests and avoid the repeated API calls:

```
'cache'     => App\Logging\CloudWatchCachePool::class, // a Psr\Cache\CacheItemPoolInterface
'cache_ttl' => 300,
```

A cache pool cannot be combined with both `create_group` and `create_stream` disabled - there would be nothing to cache.

Usage
-----

[](#usage)

Point a log channel at the driver: set `LOG_CHANNEL=cloudwatch` in your `.env`, or include `cloudwatch` in a `stack`channel, then log as usual:

```
use Illuminate\Support\Facades\Log;

Log::info('User logged in', ['id' => $user->id]);

Log::channel('cloudwatch')->error('Payment failed', ['order' => $order->id]);
```

Requirements
------------

[](#requirements)

- PHP ^8.3
- Laravel ^12.0

Testing
-------

[](#testing)

```
composer test                # PHPUnit suite in parallel via Paratest
composer test:coverage       # suite with Clover coverage output
composer test:mutation       # Infection mutation gate (min MSI 90)
composer test:mutation:full  # full mutation suite without thresholds
composer check               # static analysis and lint via qlty
composer format              # format via qlty
composer smells              # duplication / complexity smells via qlty
```

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for a list of notable changes.

Contributing
------------

[](#contributing)

Contributions are welcome. Please read [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on branching, commits, code quality, and pull requests.

Security
--------

[](#security)

If you discover a security vulnerability, please report it responsibly. See [SECURITY.md](SECURITY.md) for the disclosure policy and contact details.

License
-------

[](#license)

Licensed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance65

Regular maintenance activity

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 75% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6262ea965c244b0c946a2f29a94da05e30846c066a0b59399466216654c78fe6?d=identicon)[sinemacula](/maintainers/sinemacula)

---

Top Contributors

[![sinemacula-ben](https://avatars.githubusercontent.com/u/118753672?v=4)](https://github.com/sinemacula-ben "sinemacula-ben (3 commits)")[![sine-macula-releases[bot]](https://avatars.githubusercontent.com/in/4070845?v=4)](https://github.com/sine-macula-releases[bot] "sine-macula-releases[bot] (1 commits)")

### Embed Badge

![Health badge](/badges/sinemacula-laravel-log-cloudwatch/health.svg)

```
[![Health](https://phpackages.com/badges/sinemacula-laravel-log-cloudwatch/health.svg)](https://phpackages.com/packages/sinemacula-laravel-log-cloudwatch)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B10.9k](/packages/psr-log)[open-telemetry/api

API for OpenTelemetry PHP.

1938.5M261](/packages/open-telemetry-api)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2326.5M315](/packages/open-telemetry-sdk)[illuminated/console-logger

Logging and Notifications for Laravel Console Commands.

8676.7k](/packages/illuminated-console-logger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
