目录结构调整
This commit is contained in:
@@ -10,9 +10,19 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think;
|
||||
use think\exception\ClassNotFoundException;
|
||||
|
||||
use think\App;
|
||||
|
||||
/**
|
||||
* Class Log
|
||||
* @package think
|
||||
*
|
||||
* @method void log($msg) static
|
||||
* @method void error($msg) static
|
||||
* @method void info($msg) static
|
||||
* @method void sql($msg) static
|
||||
* @method void notice($msg) static
|
||||
* @method void alert($msg) static
|
||||
*/
|
||||
class Log
|
||||
{
|
||||
const LOG = 'log';
|
||||
@@ -30,40 +40,29 @@ class Log
|
||||
protected static $type = ['log', 'error', 'info', 'sql', 'notice', 'alert'];
|
||||
// 日志写入驱动
|
||||
protected static $driver;
|
||||
// 通知发送驱动
|
||||
protected static $alarm;
|
||||
|
||||
// 当前日志授权key
|
||||
protected static $key;
|
||||
|
||||
/**
|
||||
* 日志初始化
|
||||
* @return void
|
||||
* @param array $config
|
||||
*/
|
||||
public static function init($config = [])
|
||||
public static function init($config = [])
|
||||
{
|
||||
$type = isset($config['type']) ? $config['type'] : 'File';
|
||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\log\\driver\\' . ucwords($type);
|
||||
self::$config = $config;
|
||||
unset($config['type']);
|
||||
self::$driver = new $class($config);
|
||||
if(class_exists($class)) {
|
||||
self::$driver = new $class($config);
|
||||
} else {
|
||||
throw new ClassNotFoundException('class not exists:' . $class, $class);
|
||||
}
|
||||
// 记录初始化信息
|
||||
App::$debug && Log::record('[ LOG ] INIT ' . $type . ': ' . var_export($config, true), 'info');
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知初始化
|
||||
* @return void
|
||||
*/
|
||||
public static function alarm($config = [])
|
||||
{
|
||||
$type = isset($config['type']) ? $config['type'] : 'Email';
|
||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\log\\alarm\\' . ucwords($type);
|
||||
unset($config['type']);
|
||||
self::$alarm = new $class($config['alarm']);
|
||||
// 记录初始化信息
|
||||
App::$debug && Log::record('[ CACHE ] ALARM ' . $type . ': ' . var_export($config, true), 'info');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取日志信息
|
||||
* @param string $type 信息类型
|
||||
@@ -164,19 +163,11 @@ class Log
|
||||
return self::$driver->save($log);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送预警通知
|
||||
* @param mixed $msg 调试信息
|
||||
* @return void
|
||||
*/
|
||||
public static function send($msg)
|
||||
{
|
||||
self::$alarm && self::$alarm->send($msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 静态调用
|
||||
* @return void
|
||||
* @param $method
|
||||
* @param $args
|
||||
* @return mixed
|
||||
*/
|
||||
public static function __callStatic($method, $args)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user