相同的日志消息会持续打印到调试.log文件数千次

时间:2019-01-14 作者:Utsav Madaan

因此,我在使用Wordpress站点时,通过编写调试来调试PHP代码。使用error\\u log($message)或trigger\\u error($message)记录日志。

我在这些日志语句中的消息在调试中不断打印数千次。来自函数中声明的同一条语句的日志文件。php(例如purpose here,我从themes\'s functions.php中登录,虽然我在调试一些代码片段插件,但这会导致同一问题的多次打印)

相应地,检查此问题是否是由其函数中的代码引起的。php或代码片段插件被多次调用我尝试使用不同的机制记录日志[chrome控制台日志和chrome浏览器警报],结果是通过chrome控制台日志和;chrome浏览器警报只有一次。因此,我相信我的代码不会多次运行,但会多次打印由error\\u log或trigger\\u error打印的调试日志消息;持续打印数千次。

因此,我认为这可能是由于我当地的开发环境,而不是我在真实环境中的新wordpress安装中尝试了同样的事情,同样的事情发生了。因此,尚未找到解决方案/解释。

MY THEME\'S functions.php WITH ALL TESTED CODE:

.
.
.
//continuously keeps on printing in debug.log (many times)
$debug_log = "DEBUG-debug log";
trigger_error($debug_log);
//OR
error_log($debug_log);

//prints only one time in chrome console
$debug_console = "DEBUG-console";
echo "<script>console.log(\'$debug_console\');</script>";

//alerts only one time in chrome
$debug_alert = "DEBUG-alert";
echo "<script type=\'text/javascript\'>alert(\'$debug_alert\');</script>";
MY debug.log FILE IS LIKE THIS:

[14-Jan-2019 01:05:50 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:05:51 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:05:51 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:05:54 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:05:55 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:05:59 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:04 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:25 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:26 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:26 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:27 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:29 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:31 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:31 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:31 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:32 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:06:47 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:07:02 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:07:17 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:07:29 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:07:31 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:07:32 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:07:47 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
[14-Jan-2019 01:08:02 UTC] PHP Notice:  DEBUG-debug log in /app/public/wp-content/themes/Avada-Child-Theme/functions.php on line 15
EDIT: Question clarity要明确的是,我想说,每次加载一个页面时,日志都会打印多次(&;保持打印数千次)(因此,每次加载一个页面->;从functions.php中的单个Log语句中连续多次重复日志)

EDIT: Checked disabling WordPress Heartbeat

HEARTBEAT CODE ADDED TO functions.php:

add_action( \'init\', \'stop_heartbeat\', 1 );
function stop_heartbeat() {
    wp_deregister_script(\'heartbeat\');
}
EDIT: Checked AJAX Calls
1 个回复
SO网友:Krzysiek Dróżdż

好的,据我所知,您已经输入了以下代码:

$debug_log = "DEBUG-debug log";
trigger_error($debug_log);
//OR
error_log($debug_log);
直接在您的functionsphp`文件。

这意味着,每次functions.php 文件已加载-因此在每次请求WP时都会加载。

这意味着,每次有人查看您的页面时,都会添加新的日志项。

但是这还不是全部。。。如果您已登录,则WP会发送心跳请求。它们还将产生新的日志项。

您的日志中没有那么多同时记录的日志项,因此不太可能在同一请求中打印它们。

JS不会在AJAX调用期间执行,因此您不会多次看到它们。