goszowski / laravel-database-log-channel
Laravel数据库日志通道
v2.0.0
2021-12-21 15:13 UTC
Requires
- php: ^7.0|^7.4|^8.0
- illuminate/contracts: ^7.0|^7.4|^8.37
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- nunomaduro/collision: ^5.10
- nunomaduro/larastan: ^1.0
- orchestra/testbench: ^6.22
- pestphp/pest: ^1.10
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.4
- spatie/laravel-ray: ^1.26
README
该包提供了将日志同步或异步写入数据库的能力,同时支持其他日志通道。
安装
您可以通过composer安装此包
composer require goszowski/laravel-database-log-channel
您可以使用以下命令发布和运行迁移
php artisan vendor:publish --tag="database-log-channel-migrations"
php artisan migrate
配置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', ], ], ];
用法
use Log; Log::error('My error message');
数据清理
如果不进行清理,日志表可能会迅速积累记录。为了减轻这种情况,您应该安排每天运行数据库-日志:prune Artisan命令
$schedule->command('database-logs:prune')->daily();
默认情况下,所有超过24小时的条目都将被清理。您可以在调用命令时使用小时选项来确定保留日志数据的时间长度。例如,以下命令将删除所有超过48小时创建的记录
$schedule->command('database-logs:prune --hours=48')->daily();
更新日志
有关最近更改的更多信息,请参阅更新日志
安全漏洞
有关如何报告安全漏洞的详细信息,请参阅我们的安全策略
致谢
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件