Commit 042cf7cf authored by Sebastian Kummer's avatar Sebastian Kummer

ZP-1104 Log each device to an own file when user in specialLogUsers.

The username and deviceid are then not logged to the file (as redundant
information). 

Released under the Affero GNU General Public License (AGPL) version 3.
parent e24861b9
......@@ -44,7 +44,16 @@ class FileLog extends Log {
*/
private function getLogToUserFile() {
if ($this->log_to_user_file === false) {
$this->setLogToUserFile(preg_replace('/[^a-z0-9]/', '_', strtolower($this->GetAuthUser())) . '.log');
if (in_array(strtolower($this->GetDevid()), ['','webservice','validate'])) {
$this->setLogToUserFile(preg_replace('/[^a-z0-9]/', '_', strtolower($this->GetAuthUser())) . '.log');
}
else {
$this->setLogToUserFile(
preg_replace('/[^a-z0-9]/', '_', strtolower($this->GetAuthUser())) .'-'.
preg_replace('/[^a-z0-9]/', '_', strtolower($this->GetDevid())) .
'.log'
);
}
}
return $this->log_to_user_file;
}
......@@ -64,16 +73,20 @@ class FileLog extends Log {
/**
* Returns the string to be logged.
*
* @param int $loglevel
* @param string $message
* @param int $loglevel
* @param string $message
* @param boolean $includeUserDevice puts username and device in the string
*
* @access public
* @return string
*/
public function BuildLogString($loglevel, $message) {
public function BuildLogString($loglevel, $message, $includeUserDevice) {
$log = Utils::GetFormattedTime() .' ['. str_pad($this->GetPid(),5," ",STR_PAD_LEFT) .'] '. $this->GetLogLevelString($loglevel, $loglevel >= LOGLEVEL_INFO);
$log = Utils::GetFormattedTime() .' ['. str_pad($this->GetPid(),5," ",STR_PAD_LEFT) .'] '. $this->GetLogLevelString($loglevel, $loglevel >= LOGLEVEL_INFO) . ' ' . $this->GetUser();
if (LOGLEVEL >= LOGLEVEL_DEVICEID || (LOGUSERLEVEL >= LOGLEVEL_DEVICEID && $this->IsAuthUserInSpecialLogUsers())) {
if ($includeUserDevice) {
$log .= ' '. $this->GetUser();
}
if ($includeUserDevice && (LOGLEVEL >= LOGLEVEL_DEVICEID || (LOGUSERLEVEL >= LOGLEVEL_DEVICEID && $this->IsAuthUserInSpecialLogUsers()))) {
$log .= ' ['. $this->GetDevid() .']';
}
$log .= ' ' . $message;
......@@ -94,7 +107,7 @@ class FileLog extends Log {
* @return void
*/
protected function Write($loglevel, $message) {
$data = $this->buildLogString($loglevel, $message) . PHP_EOL;
$data = $this->buildLogString($loglevel, $message, true) . PHP_EOL;
@file_put_contents(LOGFILE, $data, FILE_APPEND);
}
......@@ -107,7 +120,7 @@ class FileLog extends Log {
* @return void
*/
public function WriteForUser($loglevel, $message) {
$data = $this->buildLogString($loglevel, $message) . PHP_EOL;
$data = $this->buildLogString($loglevel, $message, false) . PHP_EOL;
@file_put_contents(LOGFILEDIR . $this->getLogToUserFile(), $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