PHPackages                             sunergix/laravel-cloudwatch-logger - 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. sunergix/laravel-cloudwatch-logger

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

sunergix/laravel-cloudwatch-logger
==================================

AWS CloudWatch logging driver for Laravel

v1.0.0(2w ago)063MITPHPPHP ^8.1

Since May 21Pushed 2w agoCompare

[ Source](https://github.com/sunergix/laravel-cloudwatch-logger)[ Packagist](https://packagist.org/packages/sunergix/laravel-cloudwatch-logger)[ Docs](https://www.pixeledge.io/)[ RSS](/packages/sunergix-laravel-cloudwatch-logger/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (4)Versions (3)Used By (0)

Laravel CloudWatch Logger
=========================

[](#laravel-cloudwatch-logger)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3ca0b8432adc94b1873cf0d14fd8fb3a390643a40bf23027589a3f1bd115bee9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73756e65726769782f6c61726176656c2d636c6f756477617463682d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sunergix/laravel-cloudwatch-logger)[![Total Downloads](https://camo.githubusercontent.com/2443c63aee794a1f2d00ec136ed121e53cb7c2bbc4492cac6d620a25cde61b71/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73756e65726769782f6c61726176656c2d636c6f756477617463682d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sunergix/laravel-cloudwatch-logger)[![License](https://camo.githubusercontent.com/a2cd0947334b0788003673e583a9908d8b3e121f6c4c984fa75ca19c32f3e9d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f73756e65726769782f6c61726176656c2d636c6f756477617463682d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](LICENSE.txt)

AWS CloudWatch Logs handler for Laravel. It plugs into Laravel's standard logging system through Monolog, creates the configured log group and stream when needed, and sends application logs to CloudWatch.

Features
--------

[](#features)

- Laravel logging channel support through Monolog
- Automatic CloudWatch log group and log stream creation
- Optional log retention policy setup
- Sequence token discovery and retry handling
- Supports AWS access keys or the default AWS credential provider chain
- Dynamic stream placeholders for hostname, environment, and date
- Compatible with Laravel 10, 11, and 12

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

[](#requirements)

- PHP 8.1 or higher
- Laravel 10, 11, or 12
- AWS credentials with CloudWatch Logs permissions

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

[](#installation)

Install the package with Composer:

```
composer require sunergix/laravel-cloudwatch-logger
```

Laravel auto-discovers the service provider. If package auto-discovery is disabled, register the provider manually:

```
Sunergix\CloudWatchLogs\CloudWatchLogsServiceProvider::class,
```

Publish the configuration file:

```
php artisan vendor:publish --provider="Sunergix\CloudWatchLogs\CloudWatchLogsServiceProvider" --tag="config"
```

Environment
-----------

[](#environment)

Add the values you need to your `.env` file:

```
AWS_DEFAULT_REGION=us-east-1

# Optional when you use IAM roles, ECS/EKS task roles, SSO, or another AWS provider.
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=

CLOUDWATCH_LOG_GROUP=laravel-app
CLOUDWATCH_LOG_STREAM="{{env}}-{{hostname}}-{{date}}"
CLOUDWATCH_LOG_RETENTION=30
CLOUDWATCH_LOG_LEVEL=debug
```

Supported stream placeholders are resolved when the CloudWatch handler is created:

- `{{hostname}}`: server hostname
- `{{env}}`: Laravel application environment
- `{{date}}`: current date in `YYYY-MM-DD` format

Set `CLOUDWATCH_LOG_RETENTION=null` in `config/cloudwatch-logs.php` if you want CloudWatch to keep logs indefinitely.

Laravel Logging Channel
-----------------------

[](#laravel-logging-channel)

Add a CloudWatch channel to `config/logging.php`:

```
use Sunergix\CloudWatchLogs\Logging\CloudWatchLogger;
use Monolog\Formatter\JsonFormatter;

'channels' => [
    'cloudwatch' => [
        'driver' => 'monolog',
        'handler' => CloudWatchLogger::class,
        'level' => env('CLOUDWATCH_LOG_LEVEL', 'debug'),
        'formatter' => JsonFormatter::class,
    ],

    'stack' => [
        'driver' => 'stack',
        'channels' => ['daily', 'cloudwatch'],
        'ignore_exceptions' => false,
    ],
],
```

Use Laravel logging normally:

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

Log::info('User logged in', [
    'user_id' => auth()->id(),
    'ip' => request()->ip(),
]);

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

AWS Permissions
---------------

[](#aws-permissions)

The AWS user or role needs these CloudWatch Logs permissions:

```
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogGroup",
        "logs:CreateLogStream",
        "logs:DescribeLogStreams",
        "logs:PutLogEvents",
        "logs:PutRetentionPolicy"
      ],
      "Resource": "arn:aws:logs:*:*:*"
    }
  ]
}
```

If you create the log group and retention policy yourself, you can remove `logs:CreateLogGroup` and `logs:PutRetentionPolicy` from the application's runtime role.

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

[](#configuration)

The published config file is `config/cloudwatch-logs.php`.

```
return [
    'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),

    'credentials' => [
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
    ],

    'log_group' => env('CLOUDWATCH_LOG_GROUP', 'laravel-app'),
    'log_stream' => env('CLOUDWATCH_LOG_STREAM', php_uname('n')),
    'retention' => env('CLOUDWATCH_LOG_RETENTION', 30),
    'level' => env('CLOUDWATCH_LOG_LEVEL', 'debug'),
];
```

When `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` are empty, the AWS SDK uses its normal credential provider chain. This is usually best for production on AWS infrastructure.

Test A Log
----------

[](#test-a-log)

You can verify the channel from Tinker:

```
php artisan tinker
```

```
Log::channel('cloudwatch')->info('CloudWatch test log', ['time' => now()->toISOString()]);
```

Then check the configured log group and stream in the AWS CloudWatch console.

You can also add a temporary route to `routes/web.php` in your Laravel application:

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

Route::get('/test-cloudwatch-log', function () {
    Log::channel('cloudwatch')->info('CloudWatch test route log', [
        'time' => now()->toISOString(),
        'environment' => app()->environment(),
        'url' => request()->fullUrl(),
    ]);

    return response()->json([
        'message' => 'CloudWatch test log sent.',
        'log_group' => config('cloudwatch-logs.log_group'),
        'log_stream' => config('cloudwatch-logs.log_stream'),
    ]);
});
```

Open `/test-cloudwatch-log` once, confirm the log appears in CloudWatch, and then remove the route.

Troubleshooting
---------------

[](#troubleshooting)

**Logs do not appear in CloudWatch**

- Confirm `AWS_DEFAULT_REGION` matches the region you are viewing in AWS.
- Confirm the log group and stream names match your `.env` values.
- Confirm the IAM user or role has `logs:PutLogEvents` and `logs:DescribeLogStreams`.
- Check `storage/logs/laravel.log` for local application errors.

**Missing credentials**

- Set `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`, or run the app with an IAM role / task role / configured AWS profile.

**ResourceAlreadyExistsException**

- This is expected when the log group or stream already exists. The handler catches that AWS response and continues.

**InvalidSequenceTokenException**

- The handler refreshes the sequence token from the AWS error message and retries the write.

Development
-----------

[](#development)

Install dependencies:

```
composer install
```

Run the test suite:

```
composer test
```

Run a syntax check:

```
composer lint
```

Validate the Composer package metadata:

```
composer validate --strict
```

License
-------

[](#license)

The MIT License. See [LICENSE.txt](LICENSE.txt).

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance96

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

19d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5065894?v=4)[Edwin Karanja](/maintainers/edwin-karanja)[@edwin-karanja](https://github.com/edwin-karanja)

---

Top Contributors

[![haseebhashim](https://avatars.githubusercontent.com/u/36129313?v=4)](https://github.com/haseebhashim "haseebhashim (1 commits)")

---

Tags

laravelloggingawsmonologcloudwatch

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sunergix-laravel-cloudwatch-logger/health.svg)

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

###  Alternatives

[maxbanton/cwh

AWS CloudWatch Handler for Monolog library

42515.7M32](/packages/maxbanton-cwh)[bugsnag/bugsnag-laravel

Official Bugsnag notifier for Laravel applications.

90335.7M37](/packages/bugsnag-bugsnag-laravel)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45344.0k1](/packages/pressbooks-pressbooks)[naoray/laravel-github-monolog

Log driver to store logs as github issues

10822.5k](/packages/naoray-laravel-github-monolog)[phpnexus/cwh

AWS CloudWatch Handler for Monolog library

393.5M7](/packages/phpnexus-cwh)[shaffe/laravel-mail-log-channel

A package to support logging via email in Laravel

1392.4k](/packages/shaffe-laravel-mail-log-channel)

PHPackages © 2026

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