Logging activities database for laravel
adityadarma/laravel-database-logging is a Laravel package for logging activities database for laravel.
It currently has 2 GitHub stars and 792 downloads on Packagist (latest version 2.8.0).
Install it with composer require adityadarma/laravel-database-logging.
Discover more Laravel packages by adityadarma
or browse all Laravel packages to compare alternatives.
Last updated
Laravel Database Logging is a feature that allows developers to store application logs in a database, rather than the default file-based storage. This feature provides a structured and organized approach to managing application logs, making it easier to query and analyze them.
From your projects root folder in terminal run:
composer require adityadarma/laravel-database-logging
Install config and asset to record the activities to:
php artisan database-logging:install
Run the migration to add the table to record, before running please check morph key type on config to set type column:
*Note: Before migrate, please check config /config/database-logging.php type data on morp relation
php artisan migrate
Laravel Database Logging can be configured in directly in /config/database-logging.php if you published the assets.
Or you can variables to your .env file.
Here are the .env file variables available:
CONNECTION_LOGGING=mysql // remove if same connection
ENABLE_LOGGING=true
QUERY_LOGGING=false
DURATION_LOGGING=30
Events for laravel authentication scaffolding are listened for as providers and are enabled via middleware. You can add events to your routes and controllers via the middleware:
capture-logging
Example to start recording page views using middleware in web.php:
Route::group(['middleware' => ['web', 'capture-logging']], function () {
Route::get('/', 'WelcomeController@welcome')->name('welcome');
});
This middleware can be enabled/disabled in the configuration settings.
Events can be recorded directly by using the trait. When using the trait you can customize the event description.
To use the trait:
Include the call in the head of your class file:
use \AdityaDarma\LaravelDatabaseLogging\Traits\DatabaseLoggable;
Include the trait call in the opening of your class:
use DatabaseLoggable;
Set route access from file config database-logging.php
/database-loggingSet limit days data log from file config database-logging.php then run the command
database-logging:purgeThis Package is licensed under the MIT license. Enjoy!