]> source.dussan.org Git - nextcloud-server.git/commitdiff
Make the object drive the logging backend
authorBart Visscher <bartv@thisnet.nl>
Thu, 27 Jun 2013 18:10:45 +0000 (20:10 +0200)
committerBart Visscher <bartv@thisnet.nl>
Thu, 27 Jun 2013 18:10:54 +0000 (20:10 +0200)
This is the other way around then it was.

lib/legacy/log.php
lib/log.php

index 4e6642b6a2f88687bcd9b55e6d0d7be21744944d..a316051d5afdb6e26ff2ef3a681f9f65dc1337d8 100644 (file)
@@ -23,6 +23,14 @@ class OC_Log {
        const ERROR=3;
        const FATAL=4;
 
+       static private $level_funcs = array(
+               self::DEBUG     => 'debug',
+               self::INFO      => 'info',
+               self::WARN      => 'warning',
+               self::ERROR     => 'error',
+               self::FATAL     => 'emergency',
+               );
+
        static public $enabled = true;
        static protected $class = null;
 
@@ -34,12 +42,9 @@ class OC_Log {
         */
        public static function write($app, $message, $level) {
                if (self::$enabled) {
-                       if (!self::$class) {
-                               self::$class = 'OC_Log_'.ucfirst(OC_Config::getValue('log_type', 'owncloud'));
-                               call_user_func(array(self::$class, 'init'));
-                       }
-                       $log_class=self::$class;
-                       $log_class::write($app, $message, $level);
+                       $context = array('app' => $app);
+                       $func = array(self::$object, self::$level_funcs[$level]);
+                       call_user_func($func, $message, $context);
                }
        }
 
index 442872af9c432a2402c077945eee8e43c10fd854..2e26ccad2dad6ed701acbde3aeedc0521acc4fcd 100644 (file)
@@ -19,10 +19,6 @@ namespace OC;
  */
 
 class Log {
-       const NOTICE=5;
-       const CRITICAL=6;
-       const ALERT=7;
-
        /**
         * System is unusable.
         *
@@ -114,6 +110,11 @@ class Log {
                $this->log(\OC_Log::DEBUG, $message, $context);
        }
 
+       public function __construct() {
+               $this->log_class = 'OC_Log_'.ucfirst(\OC_Config::getValue('log_type', 'owncloud'));
+               call_user_func(array($this->log_class, 'init'));
+       }
+
        /**
         * Logs with an arbitrary level.
         *
@@ -127,6 +128,7 @@ class Log {
                } else {
                        $app = 'no app in context';
                }
-               \OC_Log::write($app, $message, $level);
+               $log_class=$this->log_class;
+               $log_class::write($app, $message, $level);
        }
 }