yoeriboven/laravel-log-db

A database driver for logging with Laravel
193,703 58
Install
composer require yoeriboven/laravel-log-db
Latest Version:3.0
PHP:^8.2|^8.3|^8.4|^8.5
License:MIT
Last Updated:Jun 22, 2026
Links: GitHub  ·  Packagist
Maintainer: yoeriboven

Laravel Database Logger

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package provides a custom log driver for storing Laravel log messages in the database.

Compatible with Laravel 12 and 13.

use Illuminate\Support\Facades\Log;

Log::channel('db')->info('Your message');

Installation

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
        ],
    ]   
]

Usage

To use the database channel, either:

  • Add it to the stack channel for combined logging:
// config/logging.php
return [
    'channels' => [
        'stack' => [
            'channels' => ['single', 'db'],
        ],
        // other channels
    ]
]
  • Log directly to the database:
use Illuminate\Support\Facades\Log;

Log::channel('db')->info('Your log message');

Fallback channel

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.

Pruning the logs

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();

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

631,580,251 9,707
laravel/framework

The Laravel Framework.

580,311,802 34,925
laravel/tinker

Powerful REPL for the Laravel framework.

489,754,436 7,444
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

404,034,618 608
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

384,821,166 4,658