virdiggg / log-viewer-ci3
CodeIgniter 3 默认格式日志文件的查看器
1.2.0
2023-12-04 08:13 UTC
Requires
- php: >=5.6.0
README
灵感来源于 opcodesio/log-viewer,用于laravel。
如何使用
- 使用composer安装此库
composer require virdiggg/log-viewer-ci3
- 可选,更新你的
composer.json
并添加以下行
"scripts": {
"post-install-cmd": [
"@php -r \"mkdir('controllers/api'); copy('vendor/virdiggg/log-viewer-ci3/example/Logs.php', 'controllers/api/Logs.php');\""
]
}
- 打开你的
config/config.php
,然后编辑以下行。
-$config['log_threshold'] = 0; +$config['log_threshold'] = 1;
- 可选,你可以使用
.log
扩展名,而不是默认的.php
。编辑以下行。
-$config['log_file_extension'] = ''; +$config['log_file_extension'] = 'log';
- 创建一个控制器以使用此库。例如
application/controller/App.php
。此示例为JSON格式;你可以根据需要修改它。
<?php defined('BASEPATH') or exit('No direct script access allowed');
use Virdiggg\LogViewerCI3\Viewer;
class App extends CI_Controller
{
public $logs;
public function __construct()
{
parent::__construct();
$this->logs = new Viewer();
}
public function logs()
{
// Log path
$this->logs->setPath(APPPATH . 'logs');
// Log extension
$this->logs->setExt('php');
$filterDate = $this->input->post('date') ? $this->input->post('date') : '2023-01-01';
$this->logs->setName('log-' . $filterDate);
$result = $this->logs->getLogs();
echo json_encode($result);
return;
}
}
- 打开你的网站。
https:///codeigniter/logs