tarfin-labs/laravel-cloudwatch-logger

Laravel logger for AWS Clouldwatch Log service.
195,213 20
Install
composer require tarfin-labs/laravel-cloudwatch-logger
Latest Version:v2.7.0
PHP:^7.3|^8.0|^8.1|^8.2|^8.3|^8.4
License:MIT
Last Updated:Feb 24, 2025
Links: GitHub  ·  Packagist
Maintainer: tkaratug

Laravel Logger for AWS CloudWatch

Laravel logger factory for AWS Cloudwatch Logs service.

Installation

You can install the package via composer:

composer require tarfin-labs/laravel-cloudwatch-logger

Usage

Config parameters for logging are defined at config/logging.php.

You need to add new channel as cloudwatch and copy params inside config/config.php into it.

'channels' => [
    ...

    'cloudwatch' => [
        'driver' => 'custom',
        'via' => \TarfinLabs\LaravelCloudWatchLogger\LaravelCloudWatchLoggerFactory::class,
        'aws' => [
            'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
            'version' => 'latest',
            'credentials' => [
                'key' => env('AWS_ACCESS_KEY_ID'),
                'secret' => env('AWS_SECRET_ACCESS_KEY'),
            ],
        ],
        'name' => env('CLOUDWATCH_LOG_NAME', ''),
        'group' => env('CLOUDWATCH_LOG_GROUP_NAME', env('APP_NAME') . '-' . env('APP_ENV')),
        'stream' => env('CLOUDWATCH_LOG_STREAM', 'default'),
        'retention' => env('CLOUDWATCH_LOG_RETENTION', 7),
        'level' => env('CLOUDWATCH_LOG_LEVEL', 'error'),
        'extra' => [        // In case there's extra information to be logged
            'env' => env('APP_ENV'),
            'php' => PHP_VERSION,
            'laravel' => app()->version(),
        ],
    ],
],

Change the log channel inside .env file with cloudwatch.

LOG_CHANNEL=cloudwatch

You can use Laravel's default Log class to send your logs to CloudWatch.

\Illuminate\Support\Facades\Log::info('user logged in successfully', [
    'id' => 1,
    'username' => 'JohnDoe',
    'ip' => '127.0.0.1',
]);

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email development@tarfin.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Related Packages

tarfin-labs/netgsm

netgsm channel for laravel

37,598 43
tarfin-labs/laravel-config

Key value config management for Laravel

18,479 17
tarfin-labs/laravel-spatial

Laravel package to work with geospatial data types and functions.

123,374 75

Version History

Version Released PHP Laravel License
v2.7.0 ^7.3|^8.0|^8.1|^8.2|^8.3|^8.4 ^7.0|^8.0|^9.0|^10.0|^11.0|^12.0 MIT
v2.6.0 ^7.3|^8.0|^8.1|^8.2|^8.3 ^7.0|^8.0|^9.0|^10.0|^11.0 MIT
v2.5.0 ^7.3|^8.0|^8.1|^8.2 ^7.0|^8.0|^9.0|^10.0 MIT
v2.4.0 ^7.3|^8.0|^8.1|^8.2 ^7.0|^8.0|^9.0|^10.0 MIT
v2.3.0 ^7.3|^8.0|^8.1 ^7.0|^8.0|^9.0|^10.0 MIT