mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
日志Log类增加日志写入授权Key功能
This commit is contained in:
@@ -22,12 +22,16 @@ class Log
|
|||||||
|
|
||||||
// 日志信息
|
// 日志信息
|
||||||
protected static $log = [];
|
protected static $log = [];
|
||||||
|
// 配置参数
|
||||||
|
protected static $config = [];
|
||||||
// 日志类型
|
// 日志类型
|
||||||
protected static $type = ['log', 'error', 'info', 'sql', 'notice', 'alert'];
|
protected static $type = ['log', 'error', 'info', 'sql', 'notice', 'alert'];
|
||||||
// 日志写入驱动
|
// 日志写入驱动
|
||||||
protected static $driver = null;
|
protected static $driver;
|
||||||
// 通知发送驱动
|
// 通知发送驱动
|
||||||
protected static $alarm = null;
|
protected static $alarm;
|
||||||
|
// 当前日志授权key
|
||||||
|
protected static $key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志初始化
|
* 日志初始化
|
||||||
@@ -37,6 +41,7 @@ class Log
|
|||||||
{
|
{
|
||||||
$type = isset($config['type']) ? $config['type'] : 'File';
|
$type = isset($config['type']) ? $config['type'] : 'File';
|
||||||
$class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\log\\driver\\') . ucwords($type);
|
$class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\log\\driver\\') . ucwords($type);
|
||||||
|
self::$config = $config;
|
||||||
unset($config['type']);
|
unset($config['type']);
|
||||||
self::$driver = new $class($config);
|
self::$driver = new $class($config);
|
||||||
// 记录初始化信息
|
// 记录初始化信息
|
||||||
@@ -89,6 +94,30 @@ class Log
|
|||||||
self::$log = [];
|
self::$log = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前日志记录的授权key
|
||||||
|
* @param string $key 授权key
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function key($key)
|
||||||
|
{
|
||||||
|
self::$key = $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查日志写入权限
|
||||||
|
* @param array $config 当前日志配置参数
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function check($config)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (self::$key && !empty($config['allow_key']) && !in_array(self::$key, $config['allow_key'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存调试信息
|
* 保存调试信息
|
||||||
* @return bool
|
* @return bool
|
||||||
@@ -100,6 +129,10 @@ class Log
|
|||||||
self::init(Config::get('log'));
|
self::init(Config::get('log'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!self::check(self::$config)) {
|
||||||
|
// 检测日志写入权限
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$result = self::$driver->save(self::$log);
|
$result = self::$driver->save(self::$log);
|
||||||
|
|
||||||
if ($result) {
|
if ($result) {
|
||||||
|
|||||||
Reference in New Issue
Block a user