Commit fd4ae4bb authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #630 in ZP/z-push from...

Merge pull request #630 in ZP/z-push from feature/ZP-1104-have-a-device-specific-log-file to develop

* commit '45724e4a':
  ZP-1104 Make parameter optional of BuildLogString().
  ZP-1104 Make BuildLogString calls uppercase, fix missing parameter.
parents 4c151aac 45724e4a
......@@ -75,12 +75,12 @@ class FileLog extends Log {
*
* @param int $loglevel
* @param string $message
* @param boolean $includeUserDevice puts username and device in the string
* @param boolean $includeUserDevice puts username and device in the string, default: true
*
* @access public
* @return string
*/
public function BuildLogString($loglevel, $message, $includeUserDevice) {
public function BuildLogString($loglevel, $message, $includeUserDevice = true) {
$log = Utils::GetFormattedTime() .' ['. str_pad($this->GetPid(),5," ",STR_PAD_LEFT) .'] '. $this->GetLogLevelString($loglevel, $loglevel >= LOGLEVEL_INFO);
if ($includeUserDevice) {
......@@ -107,7 +107,7 @@ class FileLog extends Log {
* @return void
*/
protected function Write($loglevel, $message) {
$data = $this->buildLogString($loglevel, $message, true) . PHP_EOL;
$data = $this->BuildLogString($loglevel, $message) . PHP_EOL;
@file_put_contents(LOGFILE, $data, FILE_APPEND);
}
......@@ -120,7 +120,7 @@ class FileLog extends Log {
* @return void
*/
public function WriteForUser($loglevel, $message) {
$data = $this->buildLogString($loglevel, $message, false) . PHP_EOL;
$data = $this->BuildLogString($loglevel, $message, false) . PHP_EOL;
@file_put_contents(LOGFILEDIR . $this->getLogToUserFile(), $data, FILE_APPEND);
}
......@@ -133,7 +133,7 @@ class FileLog extends Log {
*/
protected function afterLog($loglevel, $message) {
if ($loglevel & (LOGLEVEL_FATAL | LOGLEVEL_ERROR | LOGLEVEL_WARN)) {
$data = $this->buildLogString($loglevel, $message) . PHP_EOL;
$data = $this->BuildLogString($loglevel, $message) . PHP_EOL;
@file_put_contents(LOGERRORFILE, $data, FILE_APPEND);
}
}
......
......@@ -157,13 +157,14 @@ class Syslog extends Log {
/**
* Build the log string for syslog.
*
* @param int $loglevel
* @param string $message
* @param int $loglevel
* @param string $message
* @param boolean $includeUserDevice puts username and device in the string, default: true
*
* @access public
* @return string
*/
public function BuildLogString($loglevel, $message) {
public function BuildLogString($loglevel, $message, $includeUserDevice = true) {
$log = $this->GetLogLevelString($loglevel); // Never pad syslog log because syslog log are usually read with a software.
$log .= $this->GetUser();
if ($loglevel >= LOGLEVEL_DEVICEID) {
......@@ -191,7 +192,7 @@ class Syslog extends Log {
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
$facility = 1; // user level
$pri = ($facility * 8) + $loglevel; // multiplying the Facility number by 8 + adding the level
$data = $this->buildLogString($loglevel, $message);
$data = $this->BuildLogString($loglevel, $message);
if (strlen(trim($data)) > 0) {
$syslog_message = "<{$pri}>" . date('M d H:i:s ') . '[' . $this->GetProgramName() . ']: ' . $data;
socket_sendto($sock, $syslog_message, strlen($syslog_message), 0, $this->GetHost(), $this->GetPort());
......@@ -201,7 +202,7 @@ class Syslog extends Log {
openlog($this->GenerateProgramName(), LOG_PID, LOG_SYSLOG_FACILITY);
syslog(
$this->GetZpushLogLevelToSyslogLogLevel($loglevel),
$this->buildLogString($loglevel, $message)
$this->BuildLogString($loglevel, $message)
);
}
}
......
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