From 7ea955dcbffabada9117602d4da95914a67c17b4 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 11 Apr 2013 16:48:41 +0800 Subject: [PATCH] =?UTF-8?q?Log=E7=B1=BB=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Think/Log.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Think/Log.php b/Think/Log.php index 17506f35..bed37c7d 100644 --- a/Think/Log.php +++ b/Think/Log.php @@ -21,8 +21,12 @@ class Log { static public function init($config=[]){ $type = isset($config['type'])?$config['type']:'File'; $class = 'Think\\Log\\Driver\\'. ucwords($type); - unset($config['type']); - self::$storage = new $class($config); + if(class_exists($class)) { + unset($config['type']); + self::$storage = new $class($config); + }else{ + throw new \Exception('Log type not exists:'.$type); + } } /** @@ -67,7 +71,7 @@ class Log { } self::$log = []; } - self::$storage->write($message,$destination); + self::$storage && self::$storage->write($message,$destination); } /** @@ -79,7 +83,7 @@ class Log { * @return void */ static public function write($log,$level,$destination='') { - self::$storage->write("{$level}: {$log}",$destination); + self::$storage && self::$storage->write("{$level}: {$log}",$destination); } } \ No newline at end of file