anthonyedmonds / laravel-database-log
Store your Laravel logs in the database
Requires
- php: ^8.3
- illuminate/support: ^11
Requires (Dev)
- larastan/larastan: ^2
- laravel/pint: ^1
- orchestra/testbench: ^9
- phpunit/phpunit: ^11
This package is auto-updated.
Last update: 2024-11-11 09:57:06 UTC
README
Store your Laravel logs in the database!
Installation
- Add the library using Composer:
composer require anthonyedmonds\laravel-database-log
- The service provider will be automatically registered.
If required, you can manually register the service provider by adding it to your
bootstrap/providers.php
:return [ ... AnthonyEdmonds\GovukLaravel\Providers\GovukServiceProvider::class, ... ];
- Publish the database migration and config files using Artisan:
php artisan vendor:publish --provider="AnthonyEdmonds\LaravelDatabaseLog\DatabaseLogServiceProvider"
- Add a log channel to 'config/logging.php' based on the following:
'channels' => [ ... 'database' => [ 'driver' => 'monolog', 'handler' => AnthonyEdmonds\LaravalDatabaseLog\Handler::class, 'with' => [ 'fallback' => 'daily', ], 'level' => env('LOG_LEVEL', 'debug'), ], ... ],
- The
fallback
parameter is optional, and can point to a log to use in case the database cannot be reached. - The
level
parameter can be excluded if desired.
- The
Configuration
The configuration found at config/database-log.php
allows you to customise the following:
Cleaning up old logs
The database-log:cleanup
command is provided to remove old logs from the database as required. It takes two parameters:
You can schedule the command to run automatically by adding it to your scheduler:
Schedule::command('database-log:cleanup 90')->daily();
Usage
Whenever Laravel creates a log, whether manually or when exceptions are thrown, a new Log will be created in the database.
You are free to use those Logs in whatever fashion you see fit; no UI or other restrictions are provided by this library.
Issues and feedback
You are welcome to raise issues on Github to provide bug reports, issues, and feedback.