ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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...
 
 __construct (\SimpleSAML_Configuration $config)
 Constructor for log handlers. More...
 
 log ($level, $string)
 Log a message to its destination. More...
 
 setLogFormat ($format)
 Set the format desired for the logs. 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.

Reimplemented in SimpleSAML\Logger\StandardErrorLoggingHandler.

Definition at line 45 of file FileLoggingHandler.php.

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:51
$config
Definition: bootstrap.php:15

References $config, and SimpleSAML\Utils\Time\initTimezone().

+ 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.

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 }
$formats
Definition: date.php:77

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

◆ 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.

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

References SimpleSAML\Logger\FileLoggingHandler\$format.

Field Documentation

◆ $format

SimpleSAML\Logger\FileLoggingHandler::$format
protected

◆ $levelNames

SimpleSAML\Logger\FileLoggingHandler::$levelNames
staticprivate
Initial value:
= array(
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\Logger\ErrorLogLoggingHandler.

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: