php 在Codeginter 3的错误日志中查找路径

cbwuti44  于 2023-02-18  发布在  PHP
关注(0)|答案(1)|浏览(122)

我已经在我的网站上启动了错误日志记录。
$config\['log_threshold'\] = 1;
但是自从我开始做的那一天起,我就开始跟踪日志,比如-

ERROR - 2023-02-09 06:37:50 --> 404 Page Not Found: Assets/js
ERROR - 2023-02-09 06:37:50 --> 404 Page Not Found: Assets/js
ERROR - 2023-02-09 06:37:50 --> 404 Page Not Found: Assets/bootstrap
ERROR - 2023-02-09 06:38:05 --> 404 Page Not Found: Assets/fonts
ERROR - 2023-02-09 06:38:05 --> 404 Page Not Found: Assets/js
ERROR - 2023-02-09 06:38:05 --> 404 Page Not Found: Assets/bootstrap
ERROR - 2023-02-09 06:38:05 --> 404 Page Not Found: Assets/bootstrap
ERROR - 2023-02-09 06:38:05 --> 404 Page Not Found: Assets/js
ERROR - 2023-02-09 06:39:02 --> 404 Page Not Found: Assets/js
ERROR - 2023-02-09 06:39:02 --> 404 Page Not Found: Assets/bootstrap
ERROR - 2023-02-09 06:39:02 --> 404 Page Not Found: Assets/fonts
ERROR - 2023-02-09 06:39:02 --> 404 Page Not Found: Assets/js
ERROR - 2023-02-09 06:39:02 --> 404 Page Not Found: Assets/bootstrap
ERROR - 2023-02-09 06:39:15 --> 404 Page Not Found: Assets/bootstrap
ERROR - 2023-02-09 06:39:15 --> 404 Page Not Found: Assets/js
ERROR - 2023-02-09 06:39:15 --> 404 Page Not Found: Assets/fonts
ERROR - 2023-02-09 06:39:15 --> 404 Page Not Found: Assets/bootstrap
ERROR - 2023-02-09 06:39:15 --> 404 Page Not Found: Assets/js
ERROR - 2023-02-09 06:39:24 --> 404 Page Not Found: Repository/css

我有数以千计的网页的网站,这是真的很难理解哪个网页是产生这些错误。有什么办法我可以得到一个网页名称,产生这些错误。
我尝试将阈值更改为2,但不起作用

x0fgdtte

x0fgdtte1#

1.查看网站devtools控制台日志(Chrome中的F12),您可以看到在页面上找不到哪些文件。
1.查看服务器上的access.log
1.以前我通过在核心文件中创建两个数组来解决这个问题,您可能需要稍微重构代码,但这样会更容易理解

$this->data->js = [];
$this->data->css = [];

然后我在核心控制器中添加了所需的css和js文件:

$this->data->js[] = 'jquery';
$this->data->js[] = 'https://remote.js/file.js';

$this->data->css[] = 'bootstrap';
$this->data->css[] = 'https://google.fonts/fonts.css';

使用这个解决方案,我总是可以在控制器或类构造函数中添加一个定制的js或css(只与这个函数相关)文件

public function add_user() {
    $this->data->js[] = 'users/add_user'; //assets/js/users/add_user.js
}

然后在视图文件 Package 器中foreach <head>中的这些数组

<?php
    if(isset($css)) {
        foreach ($css as $key => $value) {
            if (preg_match('/(https?:)?\/\//', $value) === 1) {
                echo '<link rel="stylesheet" type="text/css" href="' . $value . '" />' . PHP_EOL;
            } else if (file_exists(FCPATH . 'assets/css/' . $value . '.css')) {
                echo '<link rel="stylesheet" type="text/css" href="' . site_url() . 'assets/css/' . $value . '.css?' . filemtime(FCPATH . 'assets/css/' . $value . '.css') . '" />' . PHP_EOL;
            } else {
                log_message("ERROR", $value . ' css file not found');
            }
        }
    }
    ?>

以及在</body>标签之后

<?php
if(isset($js)) {
    foreach ($js as $key => $value) {
        if (preg_match('/(https?:)?\/\//', $value) === 1) {
            echo '<script type="text/javascript" src="' . $value . '"></script>' . PHP_EOL;
        } else if (file_exists(FCPATH . '/assets/js/' . $value .'.js')) {
            echo '<script type="text/javascript" src="' . site_url() .'assets/js/'. $value . '.js?' . filemtime(FCPATH  .'assets/js/'.  $value .'.js' ) . '"></script>' . PHP_EOL;
        } else {
            log_message('ERROR',$value. ' javascript file not found');
        }
    }
}
?>

相关问题