PHP code example of sinemacula / laravel-log-cloudwatch

1. Go to this page and download the library: Download sinemacula/laravel-log-cloudwatch library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sinemacula / laravel-log-cloudwatch example snippets


'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'),
],

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

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

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

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

use Illuminate\Support\Facades\Log;

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

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