summaryrefslogtreecommitdiffstats
path: root/lib/SimpleSAML/Logger/LoggingHandlerFile.php
diff options
context:
space:
mode:
authorLasse Birnbaum Jensen <lasse@sdu.dk>2008-02-07 20:54:21 +0000
committerLasse Birnbaum Jensen <lasse@sdu.dk>2008-02-07 20:54:21 +0000
commit972c5df4d221d24265efb859901c1969def011f3 (patch)
treeb595b0973c5d5d2d55b22ae0dd3a1087eac258ba /lib/SimpleSAML/Logger/LoggingHandlerFile.php
parent3bd4122b9b119d14dea7f0c7ad089bdd44e3819f (diff)
downloadsimplesamlphp-972c5df4d221d24265efb859901c1969def011f3.zip
simplesamlphp-972c5df4d221d24265efb859901c1969def011f3.tar.gz
simplesamlphp-972c5df4d221d24265efb859901c1969def011f3.tar.bz2
Suggestion for new logger.
TrackID is always prepended to the logstring New logging options in config-template.php Possible to configure logging to use syslog or file Please test the new logging function. Logging handler has only been added. The old logging function is still uses in the code. After test all logging calls should be rewritten to the new format. Usage: Required: require_once('SimpleSAML/Logger.php'); Logging: Logger::emergency("text to log"); Logger::critical("text to log"); Logger::alert("text to log"); Logger::error("text to log"); Logger::warning("text to log"); Logger::notice("text to log"); Logger::info("text to log"); Logger::debug("text to log"); Logger::emergency("text to log"); Logger::info(array("text","to","log")); Statistics: Stats are prepended with STAT in the logfile for easier analysis. Logger::stats("SSO"); Example (syslog): Feb 7 21:02:33 server_name simpleSAMLphp[pid]: [trackid] loglevel text to log git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@268 44740490-163a-0410-bde0-09ae8108e29a
Diffstat (limited to 'lib/SimpleSAML/Logger/LoggingHandlerFile.php')
-rw-r--r--lib/SimpleSAML/Logger/LoggingHandlerFile.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/SimpleSAML/Logger/LoggingHandlerFile.php b/lib/SimpleSAML/Logger/LoggingHandlerFile.php
new file mode 100644
index 0000000..dd77cd6
--- /dev/null
+++ b/lib/SimpleSAML/Logger/LoggingHandlerFile.php
@@ -0,0 +1,34 @@
+<?php
+
+require_once('SimpleSAML/Configuration.php');
+require_once('SimpleSAML/Logger.php');
+
+class SimpleSAML_Logger_LoggingHandlerFile implements SimpleSAML_Logger_LoggingHandler {
+
+ private $logFile = null;
+
+ function __construct() {
+ $config = SimpleSAML_Configuration::getInstance();
+ assert($config instanceof SimpleSAML_Configuration);
+
+ /* Get the metadata handler option from the configuration. */
+ $this->logFile = $config->getBaseDir().'/'.$config->getValue('loggingdir').'/'.$config->getValue('logging.logfile');
+
+ 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." Loggingdir is not writeable for the webserver user.");
+ }
+ }
+
+ function log_internal($level,$string) {
+ if ($this->logFile != null) {
+ $line = sprintf("%s ssp %d %s\n",strftime("%b %d %H:%M:%S"),$level,$string);
+ file_put_contents($this->logFile,$line,FILE_APPEND);
+ }
+ }
+}
+
+?> \ No newline at end of file