From 47d5affe4804c958dc88aff39d0f8368d84b99bf Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 22 Mar 2008 18:51:50 +0000 Subject: [PATCH] Add error tracking. git-svn-id: http://htmlpurifier.org/svnroot@1620 48356398-32a2-884e-a903-53898d9a118a --- XHTMLCompiler.php | 3 ++- common.php | 2 ++ config.default.php | 15 ++++++++++++++- functions.php | 19 ++++++++++++++++++- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/XHTMLCompiler.php b/XHTMLCompiler.php index a23f79a..bf411b0 100644 --- a/XHTMLCompiler.php +++ b/XHTMLCompiler.php @@ -57,7 +57,8 @@ class XHTMLCompiler protected $configKeys = array('allowed_dirs', 'directory_index', 'indexed_dirs', 'web_path', 'web_domain', 'viewvc_url', - 'svn_headurl_munge', 'debug', 'error_xsl'); + 'svn_headurl_munge', 'debug', 'error_xsl', 'admin_email', + 'error_log', 'error_mute'); protected $config = array(); protected $filterManager; diff --git a/common.php b/common.php index cdec72e..dfc75c9 100644 --- a/common.php +++ b/common.php @@ -35,3 +35,5 @@ require_once 'XHTMLCompiler/DOMFilter.php'; set_exception_handler('xhtmlcompiler_exception_handler'); XHTMLCompiler::getInstance(); // invoke the super-object +check_errors(); +register_shutdown_function('check_errors'); diff --git a/config.default.php b/config.default.php index 07cfba8..f9d636d 100644 --- a/config.default.php +++ b/config.default.php @@ -77,4 +77,17 @@ $error_xsl = 'xhtml-compiler/error.xsl'; // error page will often be defined, in which case Apache hands the ball // to XHTML Compiler, who displays a much less informative error message. -?> \ No newline at end of file +// ** Administrator email +// Miscellaneous email notices will be mailed to this address in the event of +// errors. This will NOT be published +$admin_email = 'admin@' . $web_domain; + +// ** Error log +// Errors will be logged here. +$error_log = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'errors.log'; + +// ** Error mute semaphore file +// When this file exists, error emails will be muted. This generally gets created +// when the first error is seen, and then is deleted after the errors are +// resolved. +$error_mute = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mute.txt'; diff --git a/functions.php b/functions.php index d44cb9f..bfaaf10 100644 --- a/functions.php +++ b/functions.php @@ -186,4 +186,21 @@ function svn_log_limit($repos_url, $limit, $page = null) { return $ret; } -?> \ No newline at end of file +/** + * Checks for errors, and sends a notification email if necessary + */ +function check_errors() { + $xc = XHTMLCompiler::getInstance(); + $error_log = $xc->getConf('error_log'); + $error_mute = $xc->getConf('error_mute'); + if (file_exists($error_log) && filesize($error_log) > 0) { + if (!file_exists($error_mute)) { + mail($xc->getConf('admin_email'), 'Errors in XHTML Compiler', + "Some errors occurred in the log. No further messages\r\n". + "will be sent until the mute file [1] is deleted. You may\r\n". + "also want to delete error log file [2] after resolving any\r\n". + "issues.\r\n\r\n[1] $error_mute\r\n[2] $error_log\r\n"); + file_put_contents($error_mute, '1'); + } + } +} -- 2.11.4.GIT