ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SyslogLoggingHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace SimpleSAML\Logger;
4 
6 
15 {
16  private $isWindows = false;
17  private $format;
18 
19 
24  {
25  $facility = $config->getInteger('logging.facility', defined('LOG_LOCAL5') ? constant('LOG_LOCAL5') : LOG_USER);
26 
27  $processname = $config->getString('logging.processname', 'SimpleSAMLphp');
28 
29  // Setting facility to LOG_USER (only valid in Windows), enable log level rewrite on windows systems
30  if (System::getOS() === System::WINDOWS) {
31  $this->isWindows = true;
32  $facility = LOG_USER;
33  }
34 
35  openlog($processname, LOG_PID, $facility);
36  }
37 
38 
44  public function setLogFormat($format)
45  {
46  $this->format = $format;
47  }
48 
49 
56  public function log($level, $string)
57  {
58  // changing log level to supported levels if OS is Windows
59  if ($this->isWindows) {
60  if ($level <= 4) {
61  $level = LOG_ERR;
62  } else {
63  $level = LOG_INFO;
64  }
65  }
66 
67  $formats = array('%process', '%level');
68  $replacements = array('', $level);
69  $string = str_replace($formats, $replacements, $string);
70  $string = preg_replace('/%\w+(\{[^\}]+\})?/', '', $string);
71  $string = trim($string);
72 
73  syslog($level, $string);
74  }
75 }
$config
Definition: bootstrap.php:15
getInteger($name, $default=self::REQUIRED_OPTION)
This function retrieves an integer configuration option.
__construct(\SimpleSAML_Configuration $config)
Build a new logging handler based on syslog.
getString($name, $default=self::REQUIRED_OPTION)
This function retrieves a string configuration option.
log($level, $string)
Log a message to syslog.
setLogFormat($format)
Set the format desired for the logs.
$formats
Definition: date.php:77