Last active
August 11, 2017 05:45
-
-
Save sottwell/c8ee468226e3e732602b to your computer and use it in GitHub Desktop.
Dashboard Widget to report on Manager error log - MODX Revolution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Dashboard widget to report on the number of errors in the Error Log | |
$logfile = MODX_CORE_PATH . 'cache/logs/error.log'; | |
if(!$f = fopen($logfile, 'rb')) return 'Could not open log file.'; | |
$lines = 0; | |
while (!feof($f)) { | |
$lines += substr_count(fread($f, 8192), "(ERROR "); | |
} | |
fclose($f); | |
$link = MODX_MANAGER_URL . '?a=system/event'; | |
$lines == 1 ? $say = 'error' : $say = 'errors'; | |
$output = $lines . ' ' . $say . ' in the error log. <a href="' . $link . '">View log</a>'; | |
if($lines == 0) $output = "No errors."; | |
return $output; |
Modified to look for string (ERROR
instead of newlines. Some error messages contain several lines, thus the original widget code often didn't actually reflect the number of errors.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation:
Create a new Dashboard widget using the "Inline PHP Code" type and past in this code. Place the widget in your Dashboard.