goszowski/laravel-database-log-channel

Laravel database log channel
2,798 15
Install
composer require goszowski/laravel-database-log-channel
Latest Version:v2.0.0
PHP:^7.0|^7.4|^8.0
Laravel:7 · 8
License:MIT
Last Updated:Dec 21, 2021
Links: GitHub  ·  Packagist
Maintainer: goszowski

Laravel database log channel

Latest Version on Packagist GitHub Code Style Action Status Total Downloads

The package provides the ability to write logs into the database synchronously or asynchronously, along with other logging channels.

Installation

You can install the package via composer:

composer require goszowski/laravel-database-log-channel

You can publish and run the migrations with:

php artisan vendor:publish --tag="database-log-channel-migrations"
php artisan migrate

Configure logging.php:

return [
    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['daily', 'database'], // Add "database" channel
            'ignore_exceptions' => false,
        ],

        // ...
        'database' => [
            'driver' => 'monolog',
            'handler' => Goszowski\DatabaseLogChannel\Logging\DatabaseLogHandler::class,
            'via' => Goszowski\DatabaseLogChannel\Logging\DatabaseLogger::class,

            'alternative-log-channel' => 'daily', // Use an alternate channel when it is not possible to write to the database
            'connection' => null, // Use default connection
            'table' => 'logs',
            'async' => true, // If true, will be sent to the queue
            'queue' => 'default', // Define a queue for asynchronous logging
            'level' => 'error',
        ],

    ],
];

Usage

use Log;

Log::error('My error message');

Data Pruning

Without pruning, the logs table can accumulate records very quickly. To mitigate this, you should schedule the database-logs:prune Artisan command to run daily:

$schedule->command('database-logs:prune')->daily();

By default, all entries older than 24 hours will be pruned. You may use the hours option when calling the command to determine how long to retain Logs data. For example, the following command will delete all records created over 48 hours ago:

$schedule->command('database-logs:prune --hours=48')->daily();

Changelog

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

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

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...

644,549,754 9,698
laravel/framework

The Laravel Framework.

598,760,099 34,966
laravel/tinker

Powerful REPL for the Laravel framework.

507,193,856 7,441
laravel/serializable-closure

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

423,477,751 607
nunomaduro/collision

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

403,217,078 4,664

Version History

Version Released PHP Laravel License
v2.0.0 ^7.0|^7.4|^8.0 ^7.0|^7.4|^8.37 MIT
v1.1.6 ^7.0|^7.4|^8.0 ^7.0|^7.4|^8.37 MIT
v1.1.5 ^7.0|^7.4|^8.0 ^7.0|^8.37 MIT
v1.1.4 ^7.0|^8.0 ^7.0|^8.37 MIT
v1.1.3 ^7.2|^8.0 ^7.0|^8.37 MIT