gazatem / glog
一个 Laravel 扩展包,帮助将日志记录到数据库并发送电子邮件警报
Requires
- php: >=5.5.0
- illuminate/support: 5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0
- monolog/monolog: ^1.23|^2.0
This package is auto-updated.
Last update: 2024-08-29 04:09:12 UTC
README
Glog 帮助您的团队监控应用程序日志。Glog 与 Monolog 协同处理日志。但是,通过自定义配置,
您可以使用自定义规则和通道将日志保存到数据库。自定义通道和日志级别触发日志警报系统,并将警报发送到目标电子邮件地址。
此外,Glog 提供一个自定义管理员面板来分析日志。面板使用 Laravel 主认证系统,因此您无需保护日志控制面板。
Glog 支持 MongoDB 和 MySQL。如果您的项目需要存储更多日志,您可以使用 MongoDB。对于小型项目,MySQL 足以管理日志。
完整文档可以在 Wiki 中找到
安装
要开始使用,请使用 Composer 将包添加到您项目的依赖中
composer require gazatem/glog
Laravel 5.8 安装指南(包括 5.5 及更高版本)
如果您使用的是 Laravel 5.5 的后续版本,服务提供程序将自动注册。对于较旧版本,您需要自己完成。
打开 config/logging.php 并将以下数组项添加到配置文件中
'glog' => [ 'driver' => 'monolog', 'handler' => \Gazatem\Glog\Glog::class, ],
稍后,请勿忘记修改堆栈并添加 glog 到堆栈。这是配置的第一个项目
'stack' => [ 'driver' => 'stack', 'channels' => ['single', 'glog'], ],
Laravel 5.4 及更早版本安装指南
在 config/app.php 中打开,向提供者数组添加以下行
Gazatem\Glog\Providers\GlogServiceProvider::class
然后在您的 bootstrap/app.php 中添加/更新您的 Monolog 配置。
$app->configureMonologUsing(function ($monolog) { $monolog->pushHandler(new \Gazatem\Glog\Glog()); });
邮件警报系统
另外,将监听器添加到 app/Providers/EventServiceProvider.php 中
\Gazatem\Glog\Events\MailLog::class => [ \Gazatem\Glog\Listeners\MailListener::class, ],
发布设置
运行以下命令以发布迁移和配置
php artisan vendor:publish --provider="Gazatem\Glog\Providers\GlogServiceProvider"
迁移
要创建数据库表,请运行迁移
php artisan migrate
现在,让我们开始记录事件。
配置
所有系统配置都位于 glog.php 文件中,该文件位于 glog 目录的 config 文件夹内。此文件仅存储系统配置。添加自定义通道、更新数据库和控制面板的路由。
<?php return [ // No need to change it now, thats for future releases! 'service' => env('GLOG_SERVICE', 'local'), // Secure your log panel 'middlewares' => ['web', 'App\Http\Middleware\LogAccess'], // glog uses mysql default, but can be choose mongodb 'db_connection' => env('DB_CONNECTION', 'mysql'), // To create an alert, enter level and channel pair here // Example: 'notification' => ['test-channel' => ['CRITICAL', 'ALERT']], 'notification' => [], 'mail_subject' => 'Glog notification mail', 'mail_to' => env('MAIL_FROM'), 'translations' => [ 'test-channel' => 'A sample channel' ], // Panel route path 'route-prefix' => 'logs-panel', // All channels must be entered before to send the API. 'levels' => ['EMERGENCY', 'ALERT', 'CRITICAL', 'ERROR', 'WARNING', 'NOTICE', 'INFO', 'DEBUG'], 'channels' => ['test-channel', 'user.register'], ];
用法
不要忘记将日志包含到您的类中。
use Log;
并添加一些日志条目
Log::info('user.register', ['message' => 'User Registration Controller', 'id' => 23, 'name' => 'John Doe', 'email' => 'john@example.com']);