Skip to content

Instantly share code, notes, and snippets.

@sottwell
Last active August 11, 2017 05:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sottwell/c8ee468226e3e732602b to your computer and use it in GitHub Desktop.
Save sottwell/c8ee468226e3e732602b to your computer and use it in GitHub Desktop.
Dashboard Widget to report on Manager error log - MODX Revolution
<?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;
@sottwell
Copy link
Author

Installation:

Create a new Dashboard widget using the "Inline PHP Code" type and past in this code. Place the widget in your Dashboard.

@sottwell
Copy link
Author

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