创建在网页上显示Codeigniter日志文件的页面 [英] Create page that displays Codeigniter log files on webpage
问题描述
我有一个管理页面,我希望在我的Codeigniter的应用程序/日志文件夹中创建的所有日志消息显示在页面上。这样我就不需要进入实际的文件来查看它们,可以通过登录我的网站并点击日志页面查看它们。
I have an admin page that I would like for all of the log messages that are created in my Codeigniter's application/log folder to be displayed on the page. That way I don't have to go into the actual file to view them and could look at them by logging into my site and clicking the Logs page.
推荐答案
这是我的error_log的方式,也显示在视图上
This is the way I have my error_log and also displayed on the view
由于@Tpojka建议 file_get_contents($ file,FILE_USE_INCLUDE_PATH,null);
As @Tpojka suggested file_get_contents($file, FILE_USE_INCLUDE_PATH, null);
<?php
class Error_log extends CI_Controller {
public function index() {
$data['title'] = 'Error Log';
$data['clear'] = site_url('tool/error_log/clear');
$data['log'] = '';
// Current Filename;
$file = FCPATH . 'application/logs/' . 'log-'.date('Y-m-d').'.php';
if (file_exists($file)) {
$size = filesize($file);
if ($size >= 5242880) {
$suffix = array(
'B',
'KB',
'MB',
'GB',
'TB',
'PB',
'EB',
'ZB',
'YB'
);
$i = 0;
while (($size / 1024) > 1) {
$size = $size / 1024;
$i++;
}
$error_warning = 'Warning: Your error log file %s is %s!';
$data['error_warning'] = sprintf($error_warning, basename($file), round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i]);
} else {
// Updated from comment
$log = file_get_contents($file, FILE_USE_INCLUDE_PATH, null);
$lines = explode("\n", $log);
$content = implode("\n", array_slice($lines, 1));
$data['log'] = $content;
}
}
$this->load->view('header', $data)
$this->load->view('error_log', $data);
$this->load->view('footer');
}
}
错误日志视图
<div id="content">
<div class="container-fluid">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-exclamation-triangle"></i></h3>
</div>
<div class="panel-body">
<textarea wrap="off" rows="15" readonly class="form-control"><?php echo $log; ?></textarea>
</div>
</div>
</div>
</div>
我将config.php中的日志路径设置为默认路径,但您可以将其设置为您需要的。
I have the log path as default on config.php but you can set it to what you need.
$config['log_path'] = '';
$config['log_threshold'] = 2;
样本预览
这篇关于创建在网页上显示Codeigniter日志文件的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!