Added error logging to file or syslog.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 16 Jun 2009 09:10:20 +0000 (09:10 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 16 Jun 2009 09:10:20 +0000 (09:10 +0000)
CHANGELOG.txt
config.php
includes/errors.inc

index 501ee78ebfa01a746ee03bdd58d6ef981668e225..db28dbc005c596f24dd03cca3000e0b5d33abf1a 100644 (file)
@@ -19,6 +19,11 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+16-Jun-2009 Janusz Dobrowolski
+! Added error logging to file or syslog.
+$ /config.php
+  /includes/errors.inc
+
 15-Jun-2009 Joe Hunt
 ! Added Item Code Entry in Work Order Entry and quantity decimals now follows the item
 ! Clean-up in ui_list codes.
index c3e0d689add15b74e2039cae9763f327a0709716..20a08974b440d51621f4ddc960e516852544efa0 100644 (file)
 
 if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_to_root']))
        die("Restricted access");
-
+       // Log file for error/warning messages. Should be set to any location
+       // writable by www server. When set to empty string logging is switched off. 
+       // Special value 'syslog' can be used for system logger usage (see php manual).
+       $error_logfile = dirname(__FILE__).'/tmp/errors.log';
        $debug                  = 1;
        $show_sql               = 0;
        $go_debug               = 0;
@@ -43,6 +46,12 @@ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_
                // ini_alter("error_reporting","E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR|E_PARSE");
                ini_set("display_errors", "On");
        }
+
+       if($error_logfile != '') {
+               ini_set("error_log", $error_logfile);
+               ini_set("ignore_repeated_errors", "On");
+               ini_set("log_errors", "On");
+       }               
        // Main Title
        $app_title = "FrontAccounting";
        // application version
index 8972a9eb4b2fbe0de4fe348528acfd8153ffb2b8..eb06ff127dd84060e6469bdee5b44d16db3f0593 100644 (file)
@@ -25,8 +25,18 @@ function error_handler($errno, $errstr, $file, $line) {
     global $messages;
 
        // error_reporting==0 when messages are set off with @ 
-       if ($errno & error_reporting()) {
-               $messages[] = array($errno, $errstr, $file, $line);
+       if ($errno) {
+               if(error_reporting())
+                       $messages[] = array($errno, $errstr, $file, $line);
+
+               $ignored = E_USER_WARNING|E_USER_ERROR|E_USER_NOTICE;
+                // don't log notices hidden with @ unless in debug mode
+               if (!$go_debug) $ignored |= E_NOTICE;
+               
+               if (!($errno & $ignored))
+                        error_log(
+                        user_company().':'.$_SESSION["wa_current_user"]->loginname.':'.
+                        basename($file).":$line: $errstr");
        }
     return true;
 }