From 6b44227000b1e475ac0241fca59c12fc86bc40d0 Mon Sep 17 00:00:00 2001 From: Kevin Date: Mon, 26 Feb 2024 17:33:19 +0100 Subject: [PATCH] v 0.3.1 - Handle previous log files if no error today. --- wpuerrorlogs.php | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/wpuerrorlogs.php b/wpuerrorlogs.php index c63483d..33fa8a9 100644 --- a/wpuerrorlogs.php +++ b/wpuerrorlogs.php @@ -4,7 +4,7 @@ Plugin URI: https://github.com/WordPressUtilities/wpuerrorlogs Update URI: https://github.com/WordPressUtilities/wpuerrorlogs Description: Make sense of your log files -Version: 0.3.0 +Version: 0.3.1 Author: Darklg Author URI: https://github.com/Darklg Text Domain: wpuerrorlogs @@ -20,7 +20,7 @@ } class WPUErrorLogs { - private $plugin_version = '0.3.0'; + private $plugin_version = '0.3.1'; private $plugin_settings = array( 'id' => 'wpuerrorlogs', 'name' => 'WPU Error Logs' @@ -215,16 +215,35 @@ function sort_errors_by_latest($errors, $max_number = 5) { ---------------------------------------------------------- */ function get_logs() { + + $number_of_days = 5; + $previous_files = array(); + + /* Try to obtain previous files */ $file = ABSPATH . '/wp-content/debug.log'; - if (is_readable(WP_DEBUG_LOG)) { - $file = WP_DEBUG_LOG; + $debug_dir = dirname(WP_DEBUG_LOG); + if (is_dir($debug_dir)) { + if (is_readable(WP_DEBUG_LOG)) { + $file = WP_DEBUG_LOG; + } else { + /* Find most recent file */ + $previous_files = glob($debug_dir . '/*.log'); + arsort($previous_files); + if (isset($previous_files[0])) { + $file = array_shift($previous_files); + $previous_files = array_slice($previous_files, 0, $number_of_days); + } + } } if (!is_readable($file)) { return array(); } + /* Parse errors in files */ $errors = $this->get_logs_from_file($file); - $previous_files = $this->find_previous_log_files($file, 5); + if (empty($previous_files)) { + $previous_files = $this->find_previous_log_files($file, $number_of_days); + } foreach ($previous_files as $previous_file) { $errors_previous = $this->get_logs_from_file($previous_file); foreach ($errors_previous as $error) {