最近发现 laravel 日志查看超级超级慢
第一步:
删除日志数量,只保留 30 天(crontab)
find /www/laravel/storage/logs/ -mtime + 30 -name "*.*" -exec rm -rf {} \;
第二步:
日志压缩,之前 用 use Illuminate\Support\Facades\Log 输出 json 的
Log :: info ( $array );
改为
Log :: info ( json_encode ( $array , JSON_UNESCAPED_UNICODE));
第三步:
发现还是很慢,页面请求很快,第三方 js 的锅,哎 “局域网” 真麻烦
我直接修改第三方组件:
/www/laravel/vendor/arcanedev/log-viewer/resources/views/_template/master.blade.php
发现不生效,需要修改下面的:
/www/laravel/resources/views/vendor/log-viewer/_templatemaster.blade.php
第四步
这个之前都做了,是日志鉴权,默认是没有鉴权的,有两种方案
5.1 用 nginx 实现简单的账号密码鉴权
/www/server/nginx/conf/vhost/msite.conf
location /logs/ {
auth_basic "Authorization";
auth_basic_user_file /www/server/nginx/web.pass;
include enable-php-74.conf;
}
/www/server/pass/web.pass
yum install httpd-tools -y 确定服务器是否安装了 http
而后生成用户名密码 htpasswd -nbm pauli 12345678
使用了如上命令后,会生成加密 pauli:$apr1$nkxLxBPa$EGa.u5yKuQ08m6g/8bGb9
5.2 集成到 laravel 权限认证中
app/Http/Kernel.php
protected $middlewareGroups = ['web' => [\App\Http\Middleware\ LogAuthMiddleware :: class ,],];
app/Http/Middleware/LogAuthMiddleware.php
<?phpnamespace App\Http\Middleware ;use Closure ;use Illuminate\Http\ Request ;use Illuminate\Contracts\Auth\ Guard ;use Illuminate\Support\Facades\ Auth ;class LogAuthMiddleware {protected $auth ;public function __construct ( Guard $auth ) {$this -> auth = $auth ;}public function handle ( Request $request , Closure $next ) {if ( strpos ( $request -> getRequestUri (), '/logs' ) === 0 && (! Auth :: user () || ! Auth :: user ()-> name )) {return redirect ( '/login?redirect=' . $request -> url ());}return $next ( $request );}}
引用
https://www.cnblogs.com/zx-admin/p/17104233.html
http://www.ithov.net/index.php/php/465
- 安装:composer require rap2hpoutre/laravel-log-viewer
- 我们只需要在路由文件中添加一条路由规则即可:Route::get('logs', '\Rap2hpoutre\LaravelLogViewer\LogViewerController@index');
- 然后我们打开浏览器,输入浏览的地址:http://localhost/logs 即可看到相关的日志信息
- 如果你想重写日志的视图文件,你可以运行以下命令:php artisan vendor:publish --provider="Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider" --tag=views
运行命令之后会在/resources/views/vendor/laravel-log-viewer/中创建视图文件log.blade.php,我们可以调整这个视图文件变成我们需要的样式。