This package provides ability to store laravel log to the database table.
- PHP 8.1 - 8.4
- Laravel 9, 10, 11, 12
- install
composer require jhonoryza/laravel-database-logger
- publish config files
php artisan vendor:publish --tag laravel-database-logger
-
check the
logging-db
config file and change logger db connection. -
it is recommended to use different database connection from the main used one.
-
after package is installed, you can run
php artisan migrate
to create tablelogs_app
andlogs_api
-
then modify
logging.php
- add
database
channel to thestack
channel
<?php 'stack' => [ 'driver' => 'stack', 'channels' => ['daily', 'database'], 'ignore_exceptions' => true, ],
- add in
.env
file to setDB_CONNECTION_LOGGER=pgsql
- add
register the macro
<?php
use Jhonoryza\DatabaseLogger\Logging\ApiLogger;
class ServiceProvider
{
public function boot()
{
ApiLogger::registerMacro();
}
}
to automatically add api logger to the database call logRequest
function
<?php
use Illuminate\Support\Facades\Http;
$response = Http::logRequest()
->withHeaders(['X-Foo' => 'Bar'])
->post('https://api.example.com/v1/users?id=123', [
'name' => 'Fajar',
]);
<?php
use Jhonoryza\DatabaseLogger\Repositories\LogAppRepository;
use Jhonoryza\DatabaseLogger\Repositories\LogApiRepository;
LogAppRepository::getAllList(limit: 10);
LogAppRepository::getSimplePaginateList(perPage: 10);
LogAppRepository::getPaginateList(perPage: 10);
LogAppRepository::getCursorList(perPage: 10);
LogAppRepository::getDetail(id: 1);
LogApiRepository::getAllList(limit: 10);
LogApiRepository::getSimplePaginateList(perPage: 10);
LogApiRepository::getPaginateList(perPage: 10);
LogApiRepository::getCursorList(perPage: 10);
LogApiRepository::getDetail(id: 1);
If you've found a bug regarding security, please mail [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.