diff --git a/lib/SimpleSAML/Logger.php b/lib/SimpleSAML/Logger.php
index a951a5c527c5fe86309928a2e4014adfce65e824..8b2c66d62dd70b795500157b85fae7071aaa17bb 100644
--- a/lib/SimpleSAML/Logger.php
+++ b/lib/SimpleSAML/Logger.php
@@ -16,6 +16,9 @@ interface SimpleSAML_Logger_LoggingHandler {
 class SimpleSAML_Logger {
 	private static $loggingHandler = null;
 	private static $logLevel = null;
+	
+	private static $captureLog = FALSE;
+	private static $capturedLog = array();
 
 	/**
 	 * This constant defines the string we set the trackid to while we are fetching the
@@ -137,10 +140,20 @@ class SimpleSAML_Logger {
 		self::$loggingHandler = $sh;
 	}
 	
+	public static function setCaptureLog($val = TRUE) {
+		self::$captureLog = $val;
+	}
+	
+	public static function getCapturedLog() {
+		return self::$capturedLog;
+	}	
+	
 	static function log_internal($level,$string,$statsLog = false) {
 		if (self::$loggingHandler == null)
 			self::createLoggingHandler();
 		
+		if (self::$captureLog) self::$capturedLog[] = $string;
+		
 		if (self::$logLevel >= $level || $statsLog) {
 			if (is_array($string)) $string = implode(",",$string);
 			$string = '['.self::getTrackId().'] '.$string;