From 29c8faf11881bb770db94be0f71bed4f98d848d9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 6 Jun 2016 17:32:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97Log=E7=B1=BB=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=97=A5=E5=BF=97=E5=86=99=E5=85=A5=E6=8E=88=E6=9D=83?= =?UTF-8?q?Key=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Log.php | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/library/think/Log.php b/library/think/Log.php index d3eda965..c20911e3 100644 --- a/library/think/Log.php +++ b/library/think/Log.php @@ -22,12 +22,16 @@ class Log // 日志信息 protected static $log = []; + // 配置参数 + protected static $config = []; // 日志类型 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; /** * 日志初始化 @@ -35,8 +39,9 @@ class Log */ public static function init($config = []) { - $type = isset($config['type']) ? $config['type'] : 'File'; - $class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\log\\driver\\') . ucwords($type); + $type = isset($config['type']) ? $config['type'] : 'File'; + $class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\log\\driver\\') . ucwords($type); + self::$config = $config; unset($config['type']); self::$driver = new $class($config); // 记录初始化信息 @@ -89,6 +94,30 @@ class 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 @@ -100,6 +129,10 @@ class Log self::init(Config::get('log')); } + if (!self::check(self::$config)) { + // 检测日志写入权限 + return false; + } $result = self::$driver->save(self::$log); if ($result) {