Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 有没有一种干净的方法来解析wordpress日志?_Php_Wordpress - Fatal编程技术网

Php 有没有一种干净的方法来解析wordpress日志?

Php 有没有一种干净的方法来解析wordpress日志?,php,wordpress,Php,Wordpress,我正在做一个插件,每天检查日志错误,并通过UDP发送它们 我的想法是打开debug.log,逐行检查错误是否早于上次检查错误,然后检查是严重错误还是警告。 这很容易,但问题是一个错误可以做不止一行 有时会出现堆栈跟踪(我可以跳过它,因为它总是以#开头)。 这实际上是我的代码,但当一个错误有多行时它不起作用 $path = fs_get_wp_config_path(); $path = $path . "/wp-content/debug.log"; $logs = file($path); $

我正在做一个插件,每天检查日志错误,并通过UDP发送它们

我的想法是打开debug.log,逐行检查错误是否早于上次检查错误,然后检查是严重错误还是警告。 这很容易,但问题是一个错误可以做不止一行

有时会出现堆栈跟踪(我可以跳过它,因为它总是以#开头)。 这实际上是我的代码,但当一个错误有多行时它不起作用

$path = fs_get_wp_config_path();
$path = $path . "/wp-content/debug.log";
$logs = file($path);
$date = get_option('last_date');
if ($date == false)
{
    add_option('last_date', '27-Aug-2015 09:43:55 UTC');
    $date = get_option('last_date');
}
$last_date = new DateTime("27-Aug-2015 09:43:55 UTC");
for($i = 0; $i < count($logs); $i++)
{
     var_dump($logs[$i]);
     if (substr($logs[$i], 0, 12) == "Stack trace:")
    {
        $i++;
        while (substr($logs[$i], 0, 1) == '#' && $i < count($logs))
            $i++;
        $i++;
    }
    else
    {
        $log_date = substr($logs[$i], 1, 24);
        $new_date = new DateTime($log_date);
    //var_dump ($new_date);
    }
}

你也可以发布日志文件的样本吗?@versalle88是的,我刚刚编辑了我的帖子。
[27-Aug-2015 12:49:14 UTC] PHP Fatal error:  Uncaught exception 'Exception' with message 'DateTime::__construct(): \
Failed to parse time string (tack trace:
) at position 0 (t): The timezone could not be found in the database' in /Users/opsone/Sites/wordpress/wp-content/p\
lugins/opsonemonitoring/log.php:51
Stack trace:
#0 /Users/opsone/Sites/wordpress/wp-content/plugins/opsonemonitoring/log.php(51): DateTime->__construct('tack trace\
:\n')
#1 /Users/opsone/Sites/wordpress/wp-content/plugins/opsonemonitoring/opsonemonitoring.php(30): get_log()
#2 /Users/opsone/Sites/wordpress/wp-content/plugins/opsonemonitoring/opsonemonitoring.php(142): opsoneMonitoring()
#3 [internal function]: mysettings_page('')
#4 /Users/opsone/Sites/wordpress/wp-includes/plugin.php(496): call_user_func_array('mysettings_page', Array)
#5 /Users/opsone/Sites/wordpress/wp-admin/admin.php(212): do_action('settings_page_m...')
#6 /Users/opsone/Sites/wordpress/wp-admin/options-general.php(10): require_once('/Users/opsone/S...')
#7 {main}
  thrown in /Users/opsone/Sites/wordpress/wp-content/plugins/opsonemonitoring/log.php on line 51
[27-Aug-2015 12:52:04 UTC] PHP Fatal error:  Uncaught exception 'Exception' with message 'DateTime::__construct(): \
Failed to parse time string (tack trace:
) at position 0 (t): The timezone could not be found in the database' in /Users/opsone/Sites/wordpress/wp-content/p\
lugins/opsonemonitoring/log.php:51
Stack trace: