From a319c2aeef1f6ca698131ffb28da73d9d391f200 Mon Sep 17 00:00:00 2001
From: Cato Olsen <cato.olsen@uninett.no>
Date: Fri, 27 Mar 2009 12:31:47 +0000
Subject: [PATCH] Will now log human-readable log levels.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1448 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Logger/LoggingHandlerFile.php | 28 +++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/lib/SimpleSAML/Logger/LoggingHandlerFile.php b/lib/SimpleSAML/Logger/LoggingHandlerFile.php
index d14381038..f84d62811 100644
--- a/lib/SimpleSAML/Logger/LoggingHandlerFile.php
+++ b/lib/SimpleSAML/Logger/LoggingHandlerFile.php
@@ -10,6 +10,21 @@
  */
 
 class SimpleSAML_Logger_LoggingHandlerFile implements SimpleSAML_Logger_LoggingHandler {
+    
+	/**
+	 * This array contains the mappings from syslog loglevel to names. Copied
+	 * more or less directly from SimpleSAML_Logger_LoggingHandlerErrorLog.
+	 */
+	private static $levelNames = array(
+		LOG_EMERG => 'EMERGENCY',
+		LOG_ALERT => 'ALERT',
+		LOG_CRIT => 'CRITICAL',
+		LOG_ERR => 'ERROR',
+		LOG_WARNING => 'WARNING',
+		LOG_NOTICE => 'NOTICE',
+		LOG_INFO => 'INFO',
+		LOG_DEBUG => 'DEBUG',
+	);
 
     private $logFile = null;
     private $processname = null;
@@ -31,10 +46,17 @@ class SimpleSAML_Logger_LoggingHandlerFile implements SimpleSAML_Logger_LoggingH
         }
     }
 
-    function log_internal($level,$string) {
+    function log_internal($level, $string) {
         if ($this->logFile != null) {
-            $line = sprintf("%s %s %d %s\n",strftime("%b %d %H:%M:%S"),$this->processname,$level,$string);
-            file_put_contents($this->logFile,$line,FILE_APPEND);
+            
+            // Set human-readable log level. Copied from SimpleSAML_Logger_LoggingHandlerErrorLog.
+        	if(array_key_exists($level, self::$levelNames))
+			    $levelName = self::$levelNames[$level];
+		    else
+			    $levelName = sprintf('UNKNOWN%d', $level);
+            
+            $line = sprintf("%s %s %s %s\n", strftime("%b %d %H:%M:%S"), $this->processname, $levelName, $string);
+            file_put_contents($this->logFile, $line, FILE_APPEND);
         }
     }
 }
-- 
GitLab