SimpleSAML\Logger\FileLoggingHandler::log PHP Method

log() public method

Log a message to the log file.
public log ( integer $level, string $string )
$level integer The log level.
$string string The formatted message to log.
    public function log($level, $string)
    {
        if (!is_null($this->logFile)) {
            // set human-readable log level. Copied from SimpleSAML\Logger\ErrorLogLoggingHandler.
            $levelName = sprintf('UNKNOWN%d', $level);
            if (array_key_exists($level, self::$levelNames)) {
                $levelName = self::$levelNames[$level];
            }
            $formats = array('%process', '%level');
            $replacements = array($this->processname, $levelName);
            $matches = array();
            if (preg_match('/%date(?:\\{([^\\}]+)\\})?/', $this->format, $matches)) {
                $format = "%b %d %H:%M:%S";
                if (isset($matches[1])) {
                    $format = $matches[1];
                }
                array_push($formats, $matches[0]);
                array_push($replacements, strftime($format));
            }
            $string = str_replace($formats, $replacements, $string);
            file_put_contents($this->logFile, $string . PHP_EOL, FILE_APPEND);
        }
    }