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) { if ($title) {
$entry .= " -- $title"; $entry .= " -- $title";
} }
$this->syslog->write('info', $entry); $this->syslog->write(LOG_INFO, $entry);
} }
return true; return true;
} }

View File

@ -383,13 +383,13 @@ class Log extends AppModel
} }
} }
if ($this->syslog) { if ($this->syslog) {
$action = 'info'; $action = LOG_INFO;
if (isset($data['Log']['action'])) { if (isset($data['Log']['action'])) {
if (in_array($data['Log']['action'], self::ERROR_ACTIONS, true)) { 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)) { 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 // query
$this->Log = ClassRegistry::init('Log'); $result = $this->loadLog()->createLogEntry($user, $action, $model, $modelId, $description, $fieldsResult);
$result = $this->Log->createLogEntry($user, $action, $model, $modelId, $description, $fieldsResult);
// write to syslogd as well // write to syslogd as well
App::import('Lib', 'SysLog.SysLog'); App::import('Lib', 'SysLog.SysLog');
$syslog = new 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. * @param array $options Options for the SysLog, see above.
* @return void * @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 $option = LOG_PID; // include PID with each message
if ($options['to_stderr']) { if ($options['to_stderr']) {
$option |= LOG_PERROR; // print log message also to standard error $option |= LOG_PERROR; // print log message also to standard error
@ -51,7 +51,7 @@ class SysLog
/** /**
* Implements writing to the specified 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. * @param string $message The message you want to log.
* @return boolean success of write. * @return boolean success of write.
*/ */
@ -60,14 +60,9 @@ class SysLog
if (!$this->_log) { if (!$this->_log) {
return false; return false;
} }
$debugTypes = array('notice', 'info', 'debug'); if (!is_int($type)) {
$priority = LOG_INFO; throw new InvalidArgumentException("Invalid log type `$type`, must be one of LOG_* constant.");
if ($type == 'error' || $type == 'warning') {
$priority = LOG_ERR;
} else if (in_array($type, $debugTypes)) {
$priority = LOG_DEBUG;
} }
$output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $message; return syslog($type, $message);
return syslog($priority, $output);
} }
} }