ThinkPHP 通过网页查看最新日志文件

ThinkPHP 通过网页查看最新日志文件

做海外项目,查看日志通过 winscp 下载会比较慢,通过 xshell 实时查看等一下刷刷的就滑过去了根本看不清,这里提供个网页查看最新的。

app\controller\Log.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
namespace app\controller;

class Log extends \think\log\driver\File
{
public function index()
{
\think\facade\Log::write('查看日志');

$destination = $this->getMasterLogFile();

if(!is_file($destination)) {
return '日志文件不存在';
}

$data = file_get_contents($destination);

if($data === false) {
return '读取日志文件失败';
}

return nl2br($data);
}
}

往上