]> git.datanom.net - qtadmin.git/commitdiff
finish log method
authorMichael Rasmussen <mir@datanom.net>
Sat, 6 Jun 2015 13:50:41 +0000 (15:50 +0200)
committerMichael Rasmussen <mir@datanom.net>
Sat, 6 Jun 2015 13:50:41 +0000 (15:50 +0200)
lib/session_handler.inc.php

index 0f02690e277f760b402485893cdda836523fa2b9..09f015e5f884c60313c024c672c5d27ed58e860d 100644 (file)
@@ -1,8 +1,72 @@
 <?php
+/* vim: set ts=4 tw=0 sw=4 noet: */
+require_once $CFG->root .'config.php';
+
 class FileSessionHandler {
     private $savePath;
+    private $log_level;
+    private $log_method;
+
+    public function __construct() {
+        global $CFG;
+
+        if (isset($CFG->log_level)) {
+            $this->log_level = $CFG->log_level;
+        } else {
+            $this->log_level = 1;
+        }
+
+        if (isset($CFG->log_method)) {
+            $this->log_method = $CFG->log_method;
+        } else {
+            $this->log_level = 'syslog';
+        }
+
+        $this->log("Init FileSessionHandler", 4);
+
+    }
+
+    private function log($message, $level = 1) {
+        global $CFG;
+
+        if ($level > $this->log_level)
+            return;
+
+        $time = date('c');
+
+        $priority = LOG_INFO;
+        switch ($level) {
+            case 1: $priority = LOG_ERR; break;
+            case 2: $priority = LOG_WARNING; break;
+            case 3: $priority = LOG_INFO; break;
+            case 4: $priority = LOG_DEBUG; break;
+        }
+
+        switch ($this->log_method) {
+            case 'file':
+                if (isset($CFG->log_file)) {
+                    if ($CFG->log_file[0] == '/') {
+                        $file = $CFG->log_file;
+                    } else {
+                        $file = $CFG->root.$CFG->log_file;
+                    }
+                } else {
+                    $file = $CFG->root.'qtadmin.log';
+                }
+                file_put_contents($file, "[$time]: $message\n", FILE_APPEND | LOCK_EX);
+                chmod($file, 0600);
+                break;
+            case 'stderr':
+                file_put_contents('php://stderr', "[$time]: $message\n");
+                break;
+            case 'syslog':
+                syslog($priority, $message);
+                break;
+        }
+    }
 
-    function open($savePath, $sessionName) {
+    public function open($savePath, $sessionName) {
+        $this->log("FileSessionHandler->open", 4);
         $this->savePath = $savePath;
         if (!is_dir($this->savePath)) {
             mkdir($this->savePath, 0777);
@@ -12,6 +76,7 @@ class FileSessionHandler {
     }
 
     function close() {
+        $this->log("FileSessionHandler->close", 4);
         return true;
     }
 
@@ -20,6 +85,7 @@ class FileSessionHandler {
     }
 
     function write($id, $data) {
+        $this->log("FileSessionHandler->write : $id->$data", 4);
         $result = file_put_contents("$this->savePath/qt_sess_$id", $data);
         chmod("$this->savePath/qt_sess_$id", 0600);
 
@@ -27,6 +93,7 @@ class FileSessionHandler {
     }
 
     function destroy($id) {
+        $this->log("FileSessionHandler->destroy : $id", 4);
         $file = "$this->savePath/qt_sess_$id";
         if (file_exists($file)) {
             unlink($file);
@@ -36,6 +103,7 @@ class FileSessionHandler {
     }
 
     function gc($maxlifetime) {
+        $this->log("FileSessionHandler->gc : $maxlifetime", 4);
         foreach (glob("$this->savePath/qt_sess_*") as $file) {
             if (filemtime($file) + $maxlifetime < time() && file_exists($file)) {
                 unlink($file);
This page took 0.034955 seconds and 5 git commands to generate.