Commit 69fe72857034e134c8ce37ce85ecc069caad6f9d
1 parent
c6c75cb4
Rename the legacy log class for the legacy log.
Introduce a PEAR Log instance to log all PHP errors. Log all PHP errors to the PEAR Log instance. Optionally, if default->developmentLogWindow is set, log all PHP errors to a Javascript window. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3152 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
51 additions
and
7 deletions
config/dmsDefaults.php
| @@ -61,21 +61,31 @@ class KTInit { | @@ -61,21 +61,31 @@ class KTInit { | ||
| 61 | function setupLogging () { | 61 | function setupLogging () { |
| 62 | global $default; | 62 | global $default; |
| 63 | require_once("$default->fileSystemRoot/lib/Log.inc"); | 63 | require_once("$default->fileSystemRoot/lib/Log.inc"); |
| 64 | - $default->log = new Log($default->fileSystemRoot . "/log", $default->logLevel); | 64 | + $default->log = new KTLegacyLog($default->fileSystemRoot . "/log", $default->logLevel); |
| 65 | $res = $default->log->initialiseLogFile(); | 65 | $res = $default->log->initialiseLogFile(); |
| 66 | if (PEAR::isError($res)) { | 66 | if (PEAR::isError($res)) { |
| 67 | KTInit::handleInitError($res); | 67 | KTInit::handleInitError($res); |
| 68 | } | 68 | } |
| 69 | - $default->queryLog = new Log($default->fileSystemRoot . "/log", $default->logLevel, "query"); | 69 | + $default->queryLog = new KTLegacyLog($default->fileSystemRoot . "/log", $default->logLevel, "query"); |
| 70 | $res = $default->queryLog->initialiseLogFile(); | 70 | $res = $default->queryLog->initialiseLogFile(); |
| 71 | if (PEAR::isError($res)) { | 71 | if (PEAR::isError($res)) { |
| 72 | KTInit::handleInitError($res); | 72 | KTInit::handleInitError($res); |
| 73 | } | 73 | } |
| 74 | - $default->timerLog = new Log($default->fileSystemRoot . "/log", $default->logLevel, "timer"); | 74 | + $default->timerLog = new KTLegacyLog($default->fileSystemRoot . "/log", $default->logLevel, "timer"); |
| 75 | $res = $default->timerLog->initialiseLogFile(); | 75 | $res = $default->timerLog->initialiseLogFile(); |
| 76 | if (PEAR::isError($res)) { | 76 | if (PEAR::isError($res)) { |
| 77 | KTInit::handleInitError($res); | 77 | KTInit::handleInitError($res); |
| 78 | } | 78 | } |
| 79 | + | ||
| 80 | + require_once("Log.php"); | ||
| 81 | + $default->phpErrorLog =& Log::factory('composite'); | ||
| 82 | + $fileLog =& Log::factory('file', $default->fileSystemRoot . "/log/php_error_log", 'BLAH'); | ||
| 83 | + $default->phpErrorLog->addChild($fileLog); | ||
| 84 | + | ||
| 85 | + if ($default->developmentWindowLog) { | ||
| 86 | + $windowLog =& Log::factory('win', 'LogWindow', 'BLAH'); | ||
| 87 | + $default->phpErrorLog->addChild($windowLog); | ||
| 88 | + } | ||
| 79 | } | 89 | } |
| 80 | // }}} | 90 | // }}} |
| 81 | 91 | ||
| @@ -206,12 +216,39 @@ class KTInit { | @@ -206,12 +216,39 @@ class KTInit { | ||
| 206 | die($oError->toString()); | 216 | die($oError->toString()); |
| 207 | } | 217 | } |
| 208 | // }}} | 218 | // }}} |
| 219 | + | ||
| 220 | + // {{{ handlePHPError() | ||
| 221 | + function handlePHPError($code, $message, $file, $line) { | ||
| 222 | + global $default; | ||
| 223 | + | ||
| 224 | + /* Map the PHP error to a Log priority. */ | ||
| 225 | + switch ($code) { | ||
| 226 | + case E_WARNING: | ||
| 227 | + case E_USER_WARNING: | ||
| 228 | + $priority = PEAR_LOG_WARNING; | ||
| 229 | + break; | ||
| 230 | + case E_NOTICE: | ||
| 231 | + case E_USER_NOTICE: | ||
| 232 | + $priority = PEAR_LOG_NOTICE; | ||
| 233 | + break; | ||
| 234 | + case E_ERROR: | ||
| 235 | + case E_USER_ERROR: | ||
| 236 | + $priority = PEAR_LOG_ERR; | ||
| 237 | + break; | ||
| 238 | + default: | ||
| 239 | + $priotity = PEAR_LOG_INFO; | ||
| 240 | + } | ||
| 241 | + | ||
| 242 | + $default->phpErrorLog->log($message . ' in ' . $file . ' at line ' . $line, $priority); | ||
| 243 | + return false; | ||
| 244 | + } | ||
| 245 | + // }}} | ||
| 209 | } | 246 | } |
| 210 | // }}} | 247 | // }}} |
| 211 | 248 | ||
| 212 | // Application defaults | 249 | // Application defaults |
| 213 | // | 250 | // |
| 214 | -// Overriden in environment.php | 251 | +// Overridden in environment.php |
| 215 | 252 | ||
| 216 | $default->fileSystemRoot = KT_DIR; | 253 | $default->fileSystemRoot = KT_DIR; |
| 217 | $default->serverName = $_SERVER['HTTP_HOST']; | 254 | $default->serverName = $_SERVER['HTTP_HOST']; |
| @@ -221,11 +258,21 @@ $default->unzipCommand = "unzip"; | @@ -221,11 +258,21 @@ $default->unzipCommand = "unzip"; | ||
| 221 | $default->logLevel = 'INFO'; | 258 | $default->logLevel = 'INFO'; |
| 222 | 259 | ||
| 223 | $default->useDatabaseConfiguration = false; | 260 | $default->useDatabaseConfiguration = false; |
| 261 | +$default->developmentWindowLog = false; | ||
| 224 | 262 | ||
| 225 | // include the environment settings | 263 | // include the environment settings |
| 226 | require_once("environment.php"); | 264 | require_once("environment.php"); |
| 227 | 265 | ||
| 266 | + | ||
| 228 | KTInit::prependPath(KT_DIR . '/pear'); | 267 | KTInit::prependPath(KT_DIR . '/pear'); |
| 268 | +require_once('PEAR.php'); | ||
| 269 | + | ||
| 270 | +// instantiate log | ||
| 271 | +KTInit::setupLogging(); | ||
| 272 | + | ||
| 273 | +// Send all PHP errors to a file (and maybe a window) | ||
| 274 | +set_error_handler(array('KTInit', 'handlePHPError')); | ||
| 275 | + | ||
| 229 | KTInit::setupDB(); | 276 | KTInit::setupDB(); |
| 230 | KTInit::setupRandomSeed(); | 277 | KTInit::setupRandomSeed(); |
| 231 | 278 | ||
| @@ -253,9 +300,6 @@ if ($default->useDatabaseConfiguration && $default->system->initialised()) { | @@ -253,9 +300,6 @@ if ($default->useDatabaseConfiguration && $default->system->initialised()) { | ||
| 253 | // table mapping entries | 300 | // table mapping entries |
| 254 | include("tableMappings.inc"); | 301 | include("tableMappings.inc"); |
| 255 | 302 | ||
| 256 | -// instantiate log | ||
| 257 | -KTInit::setupLogging(); | ||
| 258 | - | ||
| 259 | KTInit::setupI18n(); | 303 | KTInit::setupI18n(); |
| 260 | 304 | ||
| 261 | KTInit::cleanGlobals(); | 305 | KTInit::cleanGlobals(); |