PHP code example of matteomeloni / cloudwatch-logs
1. Go to this page and download the library: Download matteomeloni/cloudwatch-logs 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/ */
matteomeloni / cloudwatch-logs example snippets
namespace App\Models;
use Matteomeloni\CloudwatchLogs\CloudWatchLogs;
class Log extends CloudWatchLogs
{
protected string $logGroupName = 'LOG GROUP NAME';
protected string $logStreamName = 'LOG STREAM NAME';
}
namespace App\Models;
use Matteomeloni\CloudwatchLogs\CloudWatchLogs;
class Log extends CloudWatchLogs
{
public function getFooAttribute($value)
{
return ucfirst($value);
}
}
namespace App\Models;
use Matteomeloni\CloudwatchLogs\CloudWatchLogs;
class Log extends CloudWatchLogs
{
public function setFooAttribute($value)
{
$this->attributes['foo'] = strtolower($value);
}
}
namespace App\Models;
use Matteomeloni\CloudwatchLogs\CloudWatchLogs;
class Log extends CloudWatchLogs
{
protected $casts = [
'foo' => 'boolean',
];
}
use App\Models\Log;
// All logs generated on the current day...
foreach(Logs::all() as $log) {
echo $log->attributeOne;
}
// All logs generated on custom time interval...
$logs = Logs::whereBetween('timestamp', ['Y-m-d H:i:s', 'Y-m-d H:i:s'])->get();
use App\Models\Log;
// Start a new query and retrieve the queryId string...
$queryId = Log::query()
->where('foo','bar')
->get();
// Retrieve the query results...
$logs = Log::query($queryId)->get();
// Retrieve last started query...
$logs = Log::queries();
use App\Models\Log;
//Ordering log by column asc...
Log::query()->orderBy('column')->get();
//Ordering log by column desc...
Log::query()->orderBy('column','desc')->get();
//Ordering log by column desc...
Log::query()->orderByDesc('column')->get();
use App\Models\Log;
Log::query()->take(10)->get();
Log::query()->limit(10)->get();
use App\Models\Log;
$count = Log::query()
->where('level_code', 500)
->count();
//Other types of aggregates
Log::query()->min('column');
Log::query()->max('column');
Log::query()->sum('column');
Log::query()->avg('column');
Log::query()->average('column'); //Alias for the "avg" method
use App\Models\Log;
Log::query()
->groupBy('column')
->groupBy('bin (1m)')
->count();
use App\Models\Log;
/**
* Retrieve a log by its logRecordPointer
* (you can retrieve that from the response of insight query)...
*/
$log = Log::find($ptr);
// Retrieve the first model matching the query constraints...
$log = Log::all()->first();
// Find a model by its ptr or throw an exception...
$log = Log::findOrFail($ptr);
// Find multiple models by their ptr.
$logs = Log::findMany([$ptr1,$ptr2,$ptr3]);
use App\Models\Log;
$log = new Log();
$log->attributeOne = 'foo';
$log->attributeTwo = 'bar';
$log->save();