Laravel用laravel-log-viewer记录日志

KarlXu 2020-06-16 23:31:56原创浏览量348

1:composer安装laravel-log-viewer

官方文档

composer require rap2hpoutre/laravel-log-viewer

2:在config/app.php的providers添加服务

'providers' => [
  ...
    Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider::class,
  ...
]

3:在路由器中添加路由

Route::get('logs', '\Rap2hpoutre\LaravelLogViewer\LogViewerController@index');

不需要建控制器,composer扩展包里已经建好了

4:创建view文件

php artisan vendor:publish \
  --provider="Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider" \
  --tag=views

5:在config/logging.php新增一个自定义配置

'test' => [
    'driver' => 'daily', //日志驱动模式
    'path' => storage_path('logs/laravel.log'), //文件存放目录
    'level' => 'debug', //日志等级
    'days' => 7, //只保留7天的文件

6:测试,在控制器指定新增的配置channel即可

Log::channel('test')->info([0,1,2,3,4,5,6,7,8,9]);

1592321109(1).jpg


有问题请Email联系: emkarl@163.com