Skip to content

Commit

Permalink
v 0.2.0
Browse files Browse the repository at this point in the history
- Extract from yesterday’s log if it exists.
- Fix if no logs.
- Quick Wording fixes.
  • Loading branch information
Darklg committed Feb 20, 2024
1 parent b1fa077 commit dd2b1cd
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Make sense of your log files

## Roadmap

- [x] Github actions
- [x] Parse yesterday file if it exists.
- [ ] Admin widget
- [ ] Github actions
- [ ] Store errors in database
- [ ] View details for each error : help / error times, etc
- [ ] Push top errors via slack / mail
- [ ] Parse yesterday file if it exists.
- [ ] Ignore some logs
Binary file modified lang/wpuerrorlogs-fr_FR.mo
Binary file not shown.
18 changes: 11 additions & 7 deletions lang/wpuerrorlogs-fr_FR.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: WPU Error Logs\n"
"POT-Creation-Date: 2024-02-19 18:30+0700\n"
"POT-Creation-Date: 2024-02-20 23:00+0700\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
Expand All @@ -28,26 +28,30 @@ msgstr "Réglages"
msgid "Import Settings"
msgstr "Paramètres d'importation"

#: wpuerrorlogs.php:167
#: wpuerrorlogs.php:144
msgid "Count"
msgstr "Nombre"

#: wpuerrorlogs.php:168
#: wpuerrorlogs.php:145
msgid "Date"
msgstr "Date"

#: wpuerrorlogs.php:169
#: wpuerrorlogs.php:146
msgid "Type"
msgstr "Type"

#: wpuerrorlogs.php:170
#: wpuerrorlogs.php:147
msgid "Text"
msgstr "Texte"

#: wpuerrorlogs.php:173
#: wpuerrorlogs.php:152
msgid "Top errors"
msgstr "Principales erreurs"

#: wpuerrorlogs.php:181
#: wpuerrorlogs.php:157 wpuerrorlogs.php:166
msgid "No errors at the moment."
msgstr "Pas d’erreurs pour le moment."

#: wpuerrorlogs.php:161
msgid "Latest errors"
msgstr "Dernières erreurs"
60 changes: 50 additions & 10 deletions wpuerrorlogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.1.1
Version: 0.2.0
Author: Darklg
Author URI: https://github.com/Darklg
Text Domain: wpuerrorlogs
Expand All @@ -20,7 +20,7 @@
}

class WPUErrorLogs {
private $plugin_version = '0.1.1';
private $plugin_version = '0.2.0';
private $plugin_settings = array(
'id' => 'wpuerrorlogs',
'name' => 'WPU Error Logs'
Expand Down Expand Up @@ -54,11 +54,11 @@ public function plugins_loaded() {
# CUSTOM PAGE
$admin_pages = array(
'main' => array(
'icon_url' => 'dashicons-admin-generic',
'icon_url' => 'dashicons-sos',
'menu_name' => $this->plugin_settings['name'],
'name' => 'Main page',
'name' => $this->plugin_settings['name'],
'settings_link' => true,
'settings_name' => __('Settings'),
'settings_name' => __('Settings', 'wpuerrorlogs'),
'function_content' => array(&$this,
'page_content__main'
)
Expand Down Expand Up @@ -137,7 +137,7 @@ public function page_content__main() {
return;
}

$errors = $this->extract_logs_from_file();
$errors = $this->get_logs();

/* Keep only first five and extract data */
$colnames = array(
Expand All @@ -147,19 +147,23 @@ public function page_content__main() {
'text' => __('Text', 'wpuerrorlogs')
);

/* Top errors */
$top_errors = $this->sort_errors_by_top($errors, 10);
echo '<h2>' . __('Top errors', 'wpuerrorlogs') . '</h2>';
echo $this->array_to_html_table($top_errors, array(
$html_errors = $this->array_to_html_table($top_errors, array(
'table_classname' => 'widefat',
'colnames' => $colnames
));
echo $html_errors ? $html_errors : '<p>' . __('No errors at the moment.', 'wpuerrorlogs') . '</p>';

/* Latest errors */
$latest_errors = $this->sort_errors_by_latest($errors, 10);
echo '<h2>' . __('Latest errors', 'wpuerrorlogs') . '</h2>';
echo $this->array_to_html_table($latest_errors, array(
$html_errors = $this->array_to_html_table($latest_errors, array(
'table_classname' => 'widefat',
'colnames' => $colnames
));
echo $html_errors ? $html_errors : '<p>' . __('No errors at the moment.', 'wpuerrorlogs') . '</p>';

}

Expand Down Expand Up @@ -202,12 +206,42 @@ function sort_errors_by_latest($errors, $max_number = 5) {
Extract logs from file
---------------------------------------------------------- */

function extract_logs_from_file() {

function get_logs() {
$file = ABSPATH . '/wp-content/debug.log';
if (is_readable(WP_DEBUG_LOG)) {
$file = WP_DEBUG_LOG;
}
if (!is_readable($file)) {
return array();
}

$errors = $this->get_logs_from_file($file);
$previous_file = $this->find_previous_log_file($file);
if ($previous_file) {
$errors_previous = $this->get_logs_from_file($previous_file);
$errors = $errors + $errors_previous;
}
return $errors;
}

function find_previous_log_file($file) {
$date_formats = array('Ymd', 'dmY');
foreach ($date_formats as $date_format) {
$now_date = date($date_format);
if (strpos($file, $now_date) === false) {
continue;
}
$previous_date = date($date_format, time() - 86400);
$previous_file = str_replace($now_date, $previous_date, $file);
if (is_readable($previous_file)) {
return $previous_file;
}
}

return false;
}

function get_logs_from_file($file) {

$lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$errors = [];
Expand Down Expand Up @@ -300,13 +334,19 @@ function minimize_error_text($text) {
}

function array_to_html_table($array, $args = array()) {

if (empty($array)) {
return '';
}

$default_args = array(
'table_classname' => 'widefat',
'colnames' => array()
);
if (!is_array($args)) {
$args = array();
}

$args = array_merge($default_args, $args);

$html = '<table class="' . esc_attr($args['table_classname']) . '">';
Expand Down

0 comments on commit dd2b1cd

Please sign in to comment.