ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
SimpleSAML\Logger\FileLoggingHandler Class Reference
+ Inheritance diagram for SimpleSAML\Logger\FileLoggingHandler:
+ Collaboration diagram for SimpleSAML\Logger\FileLoggingHandler:

Public Member Functions

 __construct (\SimpleSAML_Configuration $config)
 Build a new logging handler based on files. More...
 
 setLogFormat ($format)
 Set the format desired for the logs. More...
 
 log ($level, $string)
 Log a message to the log file. More...
 

Protected Attributes

 $logFile = null
 
 $processname = null
 
 $format
 

Static Private Attributes

static $levelNames
 This array contains the mappings from syslog log levels to names. More...
 

Detailed Description

Definition at line 14 of file FileLoggingHandler.php.

Constructor & Destructor Documentation

◆ __construct()

SimpleSAML\Logger\FileLoggingHandler::__construct ( \SimpleSAML_Configuration  $config)

Build a new logging handler based on files.

Implements SimpleSAML\Logger\LoggingHandlerInterface.

Definition at line 45 of file FileLoggingHandler.php.

References SimpleSAML_Configuration\getPathValue(), SimpleSAML_Configuration\getString(), and SimpleSAML\Utils\Time\initTimezone().

46  {
47  // get the metadata handler option from the configuration
48  $this->logFile = $config->getPathValue('loggingdir', 'log/').
49  $config->getString('logging.logfile', 'simplesamlphp.log');
50  $this->processname = $config->getString('logging.processname', 'SimpleSAMLphp');
51 
52  if (@file_exists($this->logFile)) {
53  if (!@is_writeable($this->logFile)) {
54  throw new \Exception("Could not write to logfile: ".$this->logFile);
55  }
56  } else {
57  if (!@touch($this->logFile)) {
58  throw new \Exception(
59  "Could not create logfile: ".$this->logFile.
60  " The logging directory is not writable for the web server user."
61  );
62  }
63  }
64 
66  }
static initTimezone()
Initialize the timezone.
Definition: Time.php:52
+ Here is the call graph for this function:

Member Function Documentation

◆ log()

SimpleSAML\Logger\FileLoggingHandler::log (   $level,
  $string 
)

Log a message to the log file.

Parameters
int$levelThe log level.
string$stringThe formatted message to log.

Implements SimpleSAML\Logger\LoggingHandlerInterface.

Definition at line 86 of file FileLoggingHandler.php.

References SimpleSAML\Logger\FileLoggingHandler\$format, $formats, array, and format.

87  {
88  if (!is_null($this->logFile)) {
89  // set human-readable log level. Copied from SimpleSAML\Logger\ErrorLogLoggingHandler.
90  $levelName = sprintf('UNKNOWN%d', $level);
91  if (array_key_exists($level, self::$levelNames)) {
92  $levelName = self::$levelNames[$level];
93  }
94 
95  $formats = array('%process', '%level');
96  $replacements = array($this->processname, $levelName);
97 
98  $matches = array();
99  if (preg_match('/%date(?:\{([^\}]+)\})?/', $this->format, $matches)) {
100  $format = "%b %d %H:%M:%S";
101  if (isset($matches[1])) {
102  $format = $matches[1];
103  }
104 
105  array_push($formats, $matches[0]);
106  array_push($replacements, strftime($format));
107  }
108 
109  $string = str_replace($formats, $replacements, $string);
110  file_put_contents($this->logFile, $string.PHP_EOL, FILE_APPEND);
111  }
112  }
Create styles array
The data for the language used.
Write to Excel2007 format
$formats
Definition: date.php:77

◆ setLogFormat()

SimpleSAML\Logger\FileLoggingHandler::setLogFormat (   $format)

Set the format desired for the logs.

Parameters
string$formatThe format used for logs.

Implements SimpleSAML\Logger\LoggingHandlerInterface.

Definition at line 74 of file FileLoggingHandler.php.

References SimpleSAML\Logger\FileLoggingHandler\$format, and format.

75  {
76  $this->format = $format;
77  }
Write to Excel2007 format

Field Documentation

◆ $format

SimpleSAML\Logger\FileLoggingHandler::$format
protected

◆ $levelNames

SimpleSAML\Logger\FileLoggingHandler::$levelNames
staticprivate
Initial value:
Logger::EMERG => 'EMERGENCY',
Logger::ALERT => 'ALERT',
Logger::CRIT => 'CRITICAL',
Logger::ERR => 'ERROR',
Logger::WARNING => 'WARNING',
Logger::NOTICE => 'NOTICE',
Logger::INFO => 'INFO',
Logger::DEBUG => 'DEBUG',
)

This array contains the mappings from syslog log levels to names.

Copied more or less directly from SimpleSAML.

Definition at line 28 of file FileLoggingHandler.php.

◆ $logFile

SimpleSAML\Logger\FileLoggingHandler::$logFile = null
protected

Definition at line 22 of file FileLoggingHandler.php.

◆ $processname

SimpleSAML\Logger\FileLoggingHandler::$processname = null
protected

Definition at line 38 of file FileLoggingHandler.php.


The documentation for this class was generated from the following file: