aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mekanisti.fi>2009-10-24 11:31:22 +0300
committerFilipp Lepalaan <filipp@mekanisti.fi>2009-10-24 11:31:22 +0300
commit46283ee631d6233c43279147191ada605308dd42 (patch)
treec22bec2a84269e76ad6da73ae8741c484dd79df7
parent08cba850d34f1e3692ec2aa9ff051fdeabe47b7f (diff)
downloadmain-46283ee631d6233c43279147191ada605308dd42.tar.gz
main-46283ee631d6233c43279147191ada605308dd42.tar.bz2
main-46283ee631d6233c43279147191ada605308dd42.zip
Error logging
-rw-r--r--App.php56
-rw-r--r--Db.php2
2 files changed, 40 insertions, 18 deletions
diff --git a/App.php b/App.php
index 89dda01..e1428d4 100644
--- a/App.php
+++ b/App.php
@@ -12,7 +12,10 @@ class App
* Fire up the application
*/
static public function init()
- {
+ {
+ // Set custom error handler
+ set_error_handler("App::error_handler");
+
@list($controller, $param, $action) = App::url();
if (empty($param)) {
@@ -91,22 +94,49 @@ class App
}
- static function ok($msg)
+ static function json($msg)
{
- $ok = array('result' => 'ok', 'msg' => $msg);
- $json = json_encode($ok);
+ $json = json_encode($msg);
header("Content-Type: application/json");
header("Content-Length: " . strlen($json));
print $json;
}
+ static function ok($msg)
+ {
+ $ok = array('result' => 'ok', 'msg' => $msg);
+ self::json($ok);
+ }
+
static function error($msg)
{
- $err = array('result' => 'error', 'msg' => $msg);
- $json = json_encode($err);
- header("Content-Type: application/json");
- header("Content-Length: " . strlen($json));
- print $json;
+ $err = array('result' => 'error', 'msg' => $msg);
+ self::json($msg);
+ self::log($msg);
+ }
+
+ /**
+ * Log an error to our own logging system
+ */
+ static function log($msg)
+ {
+ if (is_array($msg)) {
+ $msg = print_r($msg, true);
+ }
+ $c = self::conf("app.error_log");
+ $file = realpath(__FILE__."/../../../../data/$c");
+ if (!$file) {
+ return false;
+ }
+ $fh = fopen($file, "a+");
+ fwrite($fh, $msg);
+ fclose($fh);
+ }
+
+ static function error_handler($errno, $errstr, $errfile, $errline)
+ {
+ $str = sprintf("%s\t%s\t%s\t%s\n", date("d.m @ H:i:s"), basename($errfile), $errline, $errstr);
+ self::log($str);
}
/**
@@ -126,14 +156,6 @@ class App
list($loc, $lang) = explode("-", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
return sprintf("%s_%s", $loc, strtoupper($lang));
}
-
- static function log($msg)
- {
- if (is_array($msg)) {
- $msg = print_r($msg, true);
- }
- syslog(LOG_ERR, $msg);
- }
public function delete($table, $where)
{
diff --git a/Db.php b/Db.php
index 2ce5ff0..f72ba4b 100644
--- a/Db.php
+++ b/Db.php
@@ -69,7 +69,7 @@ class Db
$stmt = self::getInstance()->prepare($sql);
$result = $stmt->execute($data);
-
+
if (!$result) {
$e = $stmt->errorInfo();
exit(App::error($e[2]));