У меня есть страница администратора, которую я хотел бы получить для всех сообщений журнала, созданных в папке приложения/журнала Codeigniter, которые будут отображаться на странице. Таким образом, мне не нужно входить в фактический файл, чтобы просмотреть их и посмотреть на них, войдя в мой сайт и нажав на страницу "Журналы".
Это возможно?
Это то, как у меня есть свой error_log, а также отображается в представлении
Поскольку @Tpojka предложил 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, но вы можете настроить его на то, что вам нужно.
$config['log_path'] = '';
$config['log_threshold'] = 2;
Пример предварительного просмотра
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
чтобы он не отображался на экране?
<?php
но было бы возможно просто изучить себя.