jhonoryza / laravel-database-logger
1.0.6
2025-09-10 08:52 UTC
Requires
- php: ^8.1
- illuminate/console: ^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.24
- orchestra/testbench: ^7.0|^8.0|^9.0|^10.0
- pestphp/pest: ^4.0
- phpunit/phpunit: ^9.0|^10.0|^11.0|^12.0
README
This package provides ability to store laravel log to the database table.
Requirement
- PHP 8.1 - 8.4
- Laravel 9, 10, 11, 12
Getting Started
- 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
Additional API Logger
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', ]);
Additional Repository
<?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);
Screenshot
Security
If you've found a bug regarding security, please mail jardik.oryza@gmail.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.