Package Data | |
---|---|
Maintainer Username: | yoeriboven |
Maintainer Contact: | yoeriboven@msn.com (Yoeri Boven) |
Package Create Date: | 2022-05-18 |
Package Last Update: | 2025-02-17 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-04-13 03:00:17 |
Package Statistics | |
---|---|
Total Downloads: | 81,973 |
Monthly Downloads: | 6,716 |
Daily Downloads: | 52 |
Total Stars: | 51 |
Total Watchers: | 5 |
Total Forks: | 13 |
Total Open Issues: | 0 |
This package provides a custom log driver for storing Laravel log messages in the database.
Compatible with Laravel 9, 10 and 11.
use Illuminate\Support\Facades\Log;
Log::channel('db')->info('Your message');
Install the package via Composer:
composer require yoeriboven/laravel-log-db
Publish and run the migrations:
php artisan vendor:publish --tag="log-db-migrations"
php artisan migrate
Next, configure the database channel in config/logging.php
:
use Yoeriboven\LaravelLogDb\DatabaseLogger;
return [
'channels' => [
'db' => [
'driver' => 'custom',
'via' => DatabaseLogger::class,
'connection' => env('LOG_DB_CONNECTION'), // Optional, defaults to app's DB connection
'days' => 7, // Optional, retention period in days
'level' => env('LOG_LEVEL', 'debug'), // Optional
],
]
]
To use the database channel, either:
// config/logging.php
return [
'channels' => [
'stack' => [
'channels' => ['single', 'db'],
],
// other channels
]
]
use Illuminate\Support\Facades\Log;
Log::channel('db')->info('Your log message');
If the database is unavailable, you can define a fallback channel to handle logs:
// config/logging.php
return [
'channels' => [
'fallback' => [
'channels' => ['single'],
],
]
]
If no fallback channel is defined it will default to the single
channel.
To automatically delete logs older than a specified number of days, set the days
key in the configuration and schedule log pruning:
$schedule->command('model:prune', [
'--model' => [
\Yoeriboven\LaravelLogDb\Models\LogMessage::class,
],
])->daily();
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.