Log类改进

This commit is contained in:
thinkphp
2013-04-11 16:48:41 +08:00
parent c01c60521c
commit 7ea955dcbf

View File

@@ -21,8 +21,12 @@ class Log {
static public function init($config=[]){ static public function init($config=[]){
$type = isset($config['type'])?$config['type']:'File'; $type = isset($config['type'])?$config['type']:'File';
$class = 'Think\\Log\\Driver\\'. ucwords($type); $class = 'Think\\Log\\Driver\\'. ucwords($type);
if(class_exists($class)) {
unset($config['type']); unset($config['type']);
self::$storage = new $class($config); self::$storage = new $class($config);
}else{
throw new \Exception('Log type not exists:'.$type);
}
} }
/** /**
@@ -67,7 +71,7 @@ class Log {
} }
self::$log = []; self::$log = [];
} }
self::$storage->write($message,$destination); self::$storage && self::$storage->write($message,$destination);
} }
/** /**
@@ -79,7 +83,7 @@ class Log {
* @return void * @return void
*/ */
static public function write($log,$level,$destination='') { static public function write($log,$level,$destination='') {
self::$storage->write("{$level}: {$log}",$destination); self::$storage && self::$storage->write("{$level}: {$log}",$destination);
} }
} }