From 3d986f6ec5fbe3bce4bc99c2ce14e9064702ae96 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 18 May 2008 17:49:24 +0000 Subject: [PATCH] Revamp error log handling git-svn-id: http://htmlpurifier.org/svnroot@1732 48356398-32a2-884e-a903-53898d9a118a --- functions.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/functions.php b/functions.php index bfaaf10..5123fba 100644 --- a/functions.php +++ b/functions.php @@ -194,13 +194,24 @@ function check_errors() { $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)) { + if (file_exists($error_mute) && filesize($error_mute) == 0) { 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". + "will be sent until the mute file [1] is deleted. The\r\n". + "error log file [2] will be blanked 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'); + } elseif (!file_exists($error_mute) && file_exists($error_log)) { + $tentative_new_name = "$error_log." . date('Ymd'); + $i = 0; + $new_name = $tentative_new_name; + while (file_exists($tentative_new_name) && file_exists($new_name)) { + $new_name = "$tentative_new_name-$i"; + $i++; + } + copy($error_log, $new_name); + file_put_contents($error_log, ''); + file_put_contents($error_mute, ''); } } } -- 2.11.4.GIT