diff options
author | Jaime Perez Crespo <jaime.perez@uninett.no> | 2016-04-01 16:11:07 +0200 |
---|---|---|
committer | Jaime Perez Crespo <jaime.perez@uninett.no> | 2016-04-01 16:11:07 +0200 |
commit | ed884a147df25e7edc00ff7ede59c3adb763ca14 (patch) | |
tree | 36275787c27a6d8229bcc3bedbe602f608290933 /lib/SimpleSAML/Logger/LoggingHandlerFile.php | |
parent | 1d5b596ab432dc3db2351d3f67743fcbe16dbfeb (diff) | |
download | simplesamlphp-ed884a147df25e7edc00ff7ede59c3adb763ca14.zip simplesamlphp-ed884a147df25e7edc00ff7ede59c3adb763ca14.tar.gz simplesamlphp-ed884a147df25e7edc00ff7ede59c3adb763ca14.tar.bz2 |
Migrate all the logging handlers to namespaces. Make SimpleSAML\Logger a bit more intelligent so that it allows using custom logging handlers. Now you just need to implement SimpleSAML\Logger\LogginghandlerInterface in a class, and set the 'logging.handler' option in the configuration file to a string with the full name of your class.
Diffstat (limited to 'lib/SimpleSAML/Logger/LoggingHandlerFile.php')
-rw-r--r-- | lib/SimpleSAML/Logger/LoggingHandlerFile.php | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/lib/SimpleSAML/Logger/LoggingHandlerFile.php b/lib/SimpleSAML/Logger/LoggingHandlerFile.php deleted file mode 100644 index e1deff7..0000000 --- a/lib/SimpleSAML/Logger/LoggingHandlerFile.php +++ /dev/null @@ -1,113 +0,0 @@ -<?php - - -/** - * A class for logging - * - * @author Lasse Birnbaum Jensen, SDU. - * @author Andreas Åkre Solberg, UNINETT AS. <andreas.solberg@uninett.no> - * @package SimpleSAMLphp - */ -class SimpleSAML_Logger_LoggingHandlerFile implements SimpleSAML_Logger_LoggingHandler -{ - - /** - * A string with the path to the file where we should log our messages. - * - * @var null|string - */ - protected $logFile = null; - - /** - * This array contains the mappings from syslog log levels to names. Copied more or less directly from - * SimpleSAML_Logger_LoggingHandlerErrorLog. - */ - private static $levelNames = array( - SimpleSAML\Logger::EMERG => 'EMERGENCY', - SimpleSAML\Logger::ALERT => 'ALERT', - SimpleSAML\Logger::CRIT => 'CRITICAL', - SimpleSAML\Logger::ERR => 'ERROR', - SimpleSAML\Logger::WARNING => 'WARNING', - SimpleSAML\Logger::NOTICE => 'NOTICE', - SimpleSAML\Logger::INFO => 'INFO', - SimpleSAML\Logger::DEBUG => 'DEBUG', - ); - protected $processname = null; - protected $format; - - - /** - * Build a new logging handler based on files. - */ - public function __construct() - { - $config = SimpleSAML_Configuration::getInstance(); - assert($config instanceof SimpleSAML_Configuration); - - // get the metadata handler option from the configuration - $this->logFile = $config->getPathValue('loggingdir', 'log/'). - $config->getString('logging.logfile', 'simplesamlphp.log'); - $this->processname = $config->getString('logging.processname', 'SimpleSAMLphp'); - - if (@file_exists($this->logFile)) { - if (!@is_writeable($this->logFile)) { - throw new Exception("Could not write to logfile: ".$this->logFile); - } - } else { - if (!@touch($this->logFile)) { - throw new Exception( - "Could not create logfile: ".$this->logFile. - " The logging directory is not writable for the web server user." - ); - } - } - - SimpleSAML\Utils\Time::initTimezone(); - } - - - /** - * Set the format desired for the logs. - * - * @param string $format The format used for logs. - */ - public function setLogFormat($format) - { - $this->format = $format; - } - - - /** - * Log a message to the log file. - * - * @param int $level The log level. - * @param 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_LoggingHandlerErrorLog. - $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); - } - } -} |