[Pkg-owncloud-commits] [owncloud] 07/457: Move log level check to logger parent class

David Prévot taffit at moszumanska.debian.org
Sun Jun 28 20:05:16 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 892b5ceeebae6c2924fdea6d8e066d4df51acba5
Author: Morris Jobke <hey at morrisjobke.de>
Date:   Thu Apr 30 12:06:52 2015 +0200

    Move log level check to logger parent class
    
    * remove duplicate code from child classes
---
 lib/private/log.php          | 10 +++++--
 lib/private/log/errorlog.php |  5 +---
 lib/private/log/owncloud.php | 68 ++++++++++++++++++++++----------------------
 lib/private/log/syslog.php   |  7 ++---
 4 files changed, 45 insertions(+), 45 deletions(-)

diff --git a/lib/private/log.php b/lib/private/log.php
index 56f3678..2f15bec 100644
--- a/lib/private/log.php
+++ b/lib/private/log.php
@@ -172,7 +172,13 @@ class Log implements ILogger {
 		// interpolate replacement values into the message and return
 		$message = strtr($message, $replace);
 
-		$logger = $this->logger;
-		call_user_func(array($logger, 'write'), $app, $message, $level);
+		$config = \OC::$server->getSystemConfig();
+
+		$minLevel = min($config->getValue('loglevel', \OC_Log::WARN), \OC_Log::ERROR);
+
+		if ($level >= $minLevel) {
+			$logger = $this->logger;
+			call_user_func(array($logger, 'write'), $app, $message, $level);
+		}
 	}
 }
diff --git a/lib/private/log/errorlog.php b/lib/private/log/errorlog.php
index 007ab30..ad36051 100644
--- a/lib/private/log/errorlog.php
+++ b/lib/private/log/errorlog.php
@@ -39,10 +39,7 @@ class OC_Log_Errorlog {
 	 * @param int $level
 	 */
 	public static function write($app, $message, $level) {
-		$minLevel = min(OC_Config::getValue("loglevel", OC_Log::WARN), OC_Log::ERROR);
-		if ($level >= $minLevel) {
-			error_log('[owncloud]['.$app.'] '.$message);
-		}
+		error_log('[owncloud]['.$app.']['.$level.'] '.$message);
 	}
 }
 
diff --git a/lib/private/log/owncloud.php b/lib/private/log/owncloud.php
index 049b8db..0125164 100644
--- a/lib/private/log/owncloud.php
+++ b/lib/private/log/owncloud.php
@@ -69,40 +69,40 @@ class OC_Log_Owncloud {
 	 * @param int $level
 	 */
 	public static function write($app, $message, $level) {
-		$minLevel=min(OC_Config::getValue( "loglevel", OC_Log::WARN ), OC_Log::ERROR);
-		if($level>=$minLevel) {
-			// default to ISO8601
-			$format = OC_Config::getValue('logdateformat', 'c');
-			$logtimezone=OC_Config::getValue( "logtimezone", 'UTC' );
-			try {
-				$timezone = new DateTimeZone($logtimezone);
-			} catch (Exception $e) {
-				$timezone = new DateTimeZone('UTC');
-			}
-			$time = new DateTime(null, $timezone);
-			$request = \OC::$server->getRequest();
-			$reqId = $request->getId();
-			$remoteAddr = $request->getRemoteAddress();
-			// remove username/passwords from URLs before writing the to the log file
-			$time = $time->format($format);
-			if($minLevel == OC_Log::DEBUG) {
-				$url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '--';
-				$method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '--';
-				$entry = compact('reqId', 'remoteAddr', 'app', 'message', 'level', 'time', 'method', 'url');
-			}
-			else {
-				$entry = compact('reqId', 'remoteAddr', 'app', 'message', 'level', 'time');
-			}
-			$entry = json_encode($entry);
-			$handle = @fopen(self::$logFile, 'a');
-			@chmod(self::$logFile, 0640);
-			if ($handle) {
-				fwrite($handle, $entry."\n");
-				fclose($handle);
-			} else {
-				// Fall back to error_log
-				error_log($entry);
-			}
+		$config = \OC::$server->getSystemConfig();
+
+		// default to ISO8601
+		$format = $config->getValue('logdateformat', 'c');
+		$logtimezone = $config->getValue( "logtimezone", 'UTC' );
+		try {
+			$timezone = new DateTimeZone($logtimezone);
+		} catch (Exception $e) {
+			$timezone = new DateTimeZone('UTC');
+		}
+		$time = new DateTime(null, $timezone);
+		$request = \OC::$server->getRequest();
+		$reqId = $request->getId();
+		$remoteAddr = $request->getRemoteAddress();
+		// remove username/passwords from URLs before writing the to the log file
+		$time = $time->format($format);
+		$minLevel=min($config->getValue( "loglevel", OC_Log::WARN ), OC_Log::ERROR);
+		if($minLevel == OC_Log::DEBUG) {
+			$url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '--';
+			$method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '--';
+			$entry = compact('reqId', 'remoteAddr', 'app', 'message', 'level', 'time', 'method', 'url');
+		}
+		else {
+			$entry = compact('reqId', 'remoteAddr', 'app', 'message', 'level', 'time');
+		}
+		$entry = json_encode($entry);
+		$handle = @fopen(self::$logFile, 'a');
+		@chmod(self::$logFile, 0640);
+		if ($handle) {
+			fwrite($handle, $entry."\n");
+			fclose($handle);
+		} else {
+			// Fall back to error_log
+			error_log($entry);
 		}
 	}
 
diff --git a/lib/private/log/syslog.php b/lib/private/log/syslog.php
index 1763e6d..8595b70 100644
--- a/lib/private/log/syslog.php
+++ b/lib/private/log/syslog.php
@@ -47,10 +47,7 @@ class OC_Log_Syslog {
 	 * @param int $level
 	 */
 	public static function write($app, $message, $level) {
-		$minLevel = min(OC_Config::getValue("loglevel", OC_Log::WARN), OC_Log::ERROR);
-		if ($level >= $minLevel) {
-			$syslog_level = self::$levels[$level];
-			syslog($syslog_level, '{'.$app.'} '.$message);
-		}
+		$syslog_level = self::$levels[$level];
+		syslog($syslog_level, '{'.$app.'} '.$message);
 	}
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list