Commit 03b2995c authored by skummer's avatar skummer

ZP-386 #comment cache logs when user is not yet authenticated and write them...

ZP-386 #comment cache logs when user is not yet authenticated and write them to the user log afterwards #time 1h

git-svn-id: https://z-push.org/svn/z-push/trunk@1662 b7dd7b3b-3a3c-0410-9da9-bee62a6cc5b5
parent 67c3b0c1
...@@ -48,6 +48,8 @@ class ZLog { ...@@ -48,6 +48,8 @@ class ZLog {
static private $pidstr; static private $pidstr;
static private $wbxmlDebug = ''; static private $wbxmlDebug = '';
static private $lastLogs = array(); static private $lastLogs = array();
static private $userLog = false;
static private $unAuthCache = array();
/** /**
* Initializes the logging * Initializes the logging
...@@ -65,10 +67,11 @@ class ZLog { ...@@ -65,10 +67,11 @@ class ZLog {
if (!defined('LOGLEVEL')) if (!defined('LOGLEVEL'))
define('LOGLEVEL', LOGLEVEL_OFF); define('LOGLEVEL', LOGLEVEL_OFF);
list($user,) = Utils::SplitDomainUser(Request::GetGETUser()); list($user,) = Utils::SplitDomainUser(strtolower(Request::GetGETUser()));
self::$userLog = in_array($user, $specialLogUsers);
if (!defined('WBXML_DEBUG') && $user) { if (!defined('WBXML_DEBUG') && $user) {
// define the WBXML_DEBUG mode on user basis depending on the configurations // define the WBXML_DEBUG mode on user basis depending on the configurations
if (LOGLEVEL >= LOGLEVEL_WBXML || (LOGUSERLEVEL >= LOGLEVEL_WBXML && in_array($user, $specialLogUsers))) if (LOGLEVEL >= LOGLEVEL_WBXML || (LOGUSERLEVEL >= LOGLEVEL_WBXML && self::$userLog))
define('WBXML_DEBUG', true); define('WBXML_DEBUG', true);
else else
define('WBXML_DEBUG', false); define('WBXML_DEBUG', false);
...@@ -80,7 +83,7 @@ class ZLog { ...@@ -80,7 +83,7 @@ class ZLog {
self::$user = ''; self::$user = '';
// log the device id if the global loglevel is set to log devid or the user is in and has the right log level // log the device id if the global loglevel is set to log devid or the user is in and has the right log level
if (Request::GetDeviceID() != "" && (LOGLEVEL >= LOGLEVEL_DEVICEID || (LOGUSERLEVEL >= LOGLEVEL_DEVICEID && in_array($user, $specialLogUsers)))) if (Request::GetDeviceID() != "" && (LOGLEVEL >= LOGLEVEL_DEVICEID || (LOGUSERLEVEL >= LOGLEVEL_DEVICEID && self::$userLog)))
self::$devid = '['. Request::GetDeviceID() .'] '; self::$devid = '['. Request::GetDeviceID() .'] ';
else else
self::$devid = ''; self::$devid = '';
...@@ -105,12 +108,26 @@ class ZLog { ...@@ -105,12 +108,26 @@ class ZLog {
@file_put_contents(LOGFILE, $data, FILE_APPEND); @file_put_contents(LOGFILE, $data, FILE_APPEND);
} }
if ($loglevel <= LOGUSERLEVEL && self::logToUserFile()) { // should we write this into the user log?
if ($loglevel <= LOGUSERLEVEL && self::$userLog) {
// padd level for better reading // padd level for better reading
$data = str_replace(self::getLogLevelString($loglevel), self::getLogLevelString($loglevel,true), $data); $data = str_replace(self::getLogLevelString($loglevel), self::getLogLevelString($loglevel,true), $data);
// is the user authenticated?
if (self::logToUserFile()) {
// something was logged before the user was authenticated, write this to the log
if (!empty(self::$unAuthCache)) {
@file_put_contents(LOGFILEDIR . self::logToUserFile() . ".log", implode('', self::$unAuthCache), FILE_APPEND);
self::$unAuthCache = array();
}
// only use plain old a-z characters for the generic log file // only use plain old a-z characters for the generic log file
@file_put_contents(LOGFILEDIR . self::logToUserFile() . ".log", $data, FILE_APPEND); @file_put_contents(LOGFILEDIR . self::logToUserFile() . ".log", $data, FILE_APPEND);
} }
// the user is not authenticated yet, we save the log into memory for now
else {
self::$unAuthCache[] = $data;
}
}
if (($loglevel & LOGLEVEL_FATAL) || ($loglevel & LOGLEVEL_ERROR)) { if (($loglevel & LOGLEVEL_FATAL) || ($loglevel & LOGLEVEL_ERROR)) {
@file_put_contents(LOGERRORFILE, $data, FILE_APPEND); @file_put_contents(LOGERRORFILE, $data, FILE_APPEND);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment