chg: [syslog] Remove duplicate date and log type from log

pull/8244/head
Jakub Onderka 2022-03-27 13:05:33 +02:00
parent 4ff7cccc7a
commit 8636c1f903
4 changed files with 12 additions and 18 deletions

View File

@ -272,7 +272,7 @@ class AuditLog extends AppModel
if ($title) {
$entry .= " -- $title";
}
$this->syslog->write('info', $entry);
$this->syslog->write(LOG_INFO, $entry);
}
return true;
}

View File

@ -383,13 +383,13 @@ class Log extends AppModel
}
}
if ($this->syslog) {
$action = 'info';
$action = LOG_INFO;
if (isset($data['Log']['action'])) {
if (in_array($data['Log']['action'], self::ERROR_ACTIONS, true)) {
$action = 'err';
$action = LOG_ERR;
}
if (in_array($data['Log']['action'], self::WARNING_ACTIONS, true)) {
$action = 'warning';
$action = LOG_WARNING;
}
}

View File

@ -1223,13 +1223,12 @@ class User extends AppModel
}
// query
$this->Log = ClassRegistry::init('Log');
$result = $this->Log->createLogEntry($user, $action, $model, $modelId, $description, $fieldsResult);
$result = $this->loadLog()->createLogEntry($user, $action, $model, $modelId, $description, $fieldsResult);
// write to syslogd as well
App::import('Lib', 'SysLog.SysLog');
$syslog = new SysLog();
$syslog->write('notice', "$description -- $action" . (empty($fieldsResult) ? '' : ' -- ' . $result['Log']['change']));
$syslog->write(LOG_NOTICE, "$description -- $action" . (empty($fieldsResult) ? '' : ' -- ' . $result['Log']['change']));
}
/**

View File

@ -38,9 +38,9 @@ class SysLog
* @param array $options Options for the SysLog, see above.
* @return void
*/
public function __construct($options = array())
public function __construct($options = [])
{
$options += array('ident' => LOGS, 'facility' => LOG_LOCAL0, 'to_stderr' => true);
$options += ['ident' => LOGS, 'facility' => LOG_LOCAL0, 'to_stderr' => true];
$option = LOG_PID; // include PID with each message
if ($options['to_stderr']) {
$option |= LOG_PERROR; // print log message also to standard error
@ -51,7 +51,7 @@ class SysLog
/**
* Implements writing to the specified syslog
*
* @param string $type The type of log you are making.
* @param int $type The type of log you are making.
* @param string $message The message you want to log.
* @return boolean success of write.
*/
@ -60,14 +60,9 @@ class SysLog
if (!$this->_log) {
return false;
}
$debugTypes = array('notice', 'info', 'debug');
$priority = LOG_INFO;
if ($type == 'error' || $type == 'warning') {
$priority = LOG_ERR;
} else if (in_array($type, $debugTypes)) {
$priority = LOG_DEBUG;
if (!is_int($type)) {
throw new InvalidArgumentException("Invalid log type `$type`, must be one of LOG_* constant.");
}
$output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $message;
return syslog($priority, $output);
return syslog($type, $message);
}
}