48 $this->logFile =
$config->getPathValue(
'loggingdir',
'log/').
49 $config->getString(
'logging.logfile',
'simplesamlphp.log');
50 $this->processname =
$config->getString(
'logging.processname',
'SimpleSAMLphp');
52 if (@file_exists($this->logFile)) {
53 if (!@is_writeable($this->logFile)) {
54 throw new \Exception(
"Could not write to logfile: ".$this->logFile);
57 if (!@touch($this->logFile)) {
59 "Could not create logfile: ".$this->logFile.
60 " The logging directory is not writable for the web server user."
86 public function log($level, $string)
88 if (!is_null($this->logFile)) {
90 $levelName =
sprintf(
'UNKNOWN%d', $level);
91 if (array_key_exists($level, self::$levelNames)) {
92 $levelName = self::$levelNames[$level];
95 $formats = array(
'%process',
'%level');
96 $replacements = array($this->processname, $levelName);
99 if (preg_match(
'/%date(?:\{([^\}]+)\})?/', $this->format, $matches)) {
101 if (isset($matches[1])) {
106 array_push($replacements, strftime(
$format));
109 $string = str_replace(
$formats, $replacements, $string);
110 file_put_contents($this->logFile, $string.PHP_EOL, FILE_APPEND);
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
setLogFormat($format)
Set the format desired for the logs.
static $levelNames
This array contains the mappings from syslog log levels to names.
log($level, $string)
Log a message to the log file.
__construct(\SimpleSAML_Configuration $config)
Build a new logging handler based on files.
static initTimezone()
Initialize the timezone.