最近在Hyperf中需要用到使用路由在線查看文件日志的功能,沒有發(fā)現(xiàn)比較好用的,自己簡單寫了一個,支持查看和簡單的內(nèi)容搜索。
一、界面
先上效果圖:
二、使用
- 1.安裝組件
composer require sett/hyperf-log-viewer
- 2.發(fā)布配置文件
php bin/hyperf.php vendor:publish sett/hyperf-log-viewer
- 3.注冊路由
Router::get('/logs', 'SettLogViewerControllerLogViewController@index');
- 4.安裝view組件
composer require hyperf/view
- 5.安裝模板引擎
composer require sy-records/think-template
- 6.配置視圖
在configautoloadviewe.php文件中(如果不存在,自行創(chuàng)建),添加如下視圖配置
return [ 'engine' => ThinkEngine::class, 'mode' => Mode::TASK, 'config' => [ // 若下列文件夾不存在請自行創(chuàng)建 'view_path' => BASE_PATH . '/storage/view/', 'cache_path' => BASE_PATH . '/runtime/view/', ],];
- 7.配置組件參數(shù)
在configautoloadlogViewer.php文件中,添加自己的日志文件目錄
return [ "path" => BASE_PATH . "/runtime/logs/", "pattern" => "*.log", "size" => 10 ];
三、說明
- 日志時間格式只支持年月日時分秒格式,否則可能看不到記錄