From 62511f3444887e7617518ba4c4385b95f6d78624 Mon Sep 17 00:00:00 2001 From: Michael Rasmussen Date: Sat, 6 Jun 2015 15:50:41 +0200 Subject: [PATCH] finish log method --- lib/session_handler.inc.php | 70 ++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/lib/session_handler.inc.php b/lib/session_handler.inc.php index 0f02690..09f015e 100644 --- a/lib/session_handler.inc.php +++ b/lib/session_handler.inc.php @@ -1,8 +1,72 @@ 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); -- 2.39.2