From 717e103b004f87512296f7b961aa0b9d748051ce Mon Sep 17 00:00:00 2001
From: Lasse Birnbaum Jensen <lasse@sdu.dk>
Date: Tue, 19 Feb 2008 13:47:11 +0000
Subject: [PATCH] Changed Logging Handler for Syslog.

Now compatible with logging on Windows servers (Eventlog). Solution done from suggestions. Windows server owners please verify this fix.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@316 44740490-163a-0410-bde0-09ae8108e29a
---
 .../Logger/LoggingHandlerSyslog.php           | 23 ++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/lib/SimpleSAML/Logger/LoggingHandlerSyslog.php b/lib/SimpleSAML/Logger/LoggingHandlerSyslog.php
index a897b9117..68739ff92 100644
--- a/lib/SimpleSAML/Logger/LoggingHandlerSyslog.php
+++ b/lib/SimpleSAML/Logger/LoggingHandlerSyslog.php
@@ -14,13 +14,34 @@ require_once('SimpleSAML/Logger.php');
 
 class SimpleSAML_Logger_LoggingHandlerSyslog implements SimpleSAML_Logger_LoggingHandler {
 
+	private $isWindows = false;
+	
     function __construct() {
         $config = SimpleSAML_Configuration::getInstance();
         assert($config instanceof SimpleSAML_Configuration);
-        openlog("simpleSAMLphp", LOG_PID, $config->getValue('logging.facility') );
+        $facility = $config->getValue('logging.facility');
+        /*
+         * OS Check 
+         * Setting facility to LOG_USER (only valid in Windows), enable log level rewrite on windows systems.
+         */
+        if (substr(strtoupper(PHP_OS),0,3) == 'WIN') {
+        	$this->isWindows = true;
+        	$facility = LOG_USER;
+        }
+        	
+        openlog("simpleSAMLphp", LOG_PID, $facility);
     }
 
     function log_internal($level,$string) {
+    	/*
+    	 * Changing log level to supported levels if OS is Windows
+    	 */
+    	if ($this->isWindows) {
+    		if ($level <= 4)
+				$level = LOG_ERR;
+			else
+				$level = LOG_INFO;			
+    	}
         syslog($level,$level.' '.$string);
     }
 }
-- 
GitLab