From 81ff60592aadbdb2844d17b6c415acb86db061ef Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 4 Jul 2016 18:20:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E8=AE=B0=E5=BD=95=E7=BA=A7=E5=88=AB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 6 ++++-- library/think/Log.php | 26 +++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/convention.php b/convention.php index f3523b5c..fd7c16fd 100644 --- a/convention.php +++ b/convention.php @@ -145,9 +145,11 @@ return [ 'log' => [ // 日志记录方式,内置 file sae 支持扩展 - 'type' => 'File', + 'type' => 'File', // 日志保存目录 - 'path' => LOG_PATH, + 'path' => LOG_PATH, + // 日志记录级别 + 'level' => [], ], // +---------------------------------------------------------------------- diff --git a/library/think/Log.php b/library/think/Log.php index 1db7dc13..135f6547 100644 --- a/library/think/Log.php +++ b/library/think/Log.php @@ -132,8 +132,21 @@ class Log // 检测日志写入权限 return false; } - $result = self::$driver->save(self::$log); + if (empty(self::$config['level'])) { + // 获取全部日志 + $log = self::$log; + } else { + // 记录允许级别 + $log = []; + foreach (self::$config['level'] as $level) { + if (isset(self::$log[$level])) { + $log[$level] = self::$log[$level]; + } + } + } + + $result = self::$driver->save($log); if ($result) { self::$log = []; } @@ -147,12 +160,19 @@ class Log * 实时写入日志信息 并支持行为 * @param mixed $msg 调试信息 * @param string $type 信息类型 + * @param bool $force 是否强制写入 * @return bool */ - public static function write($msg, $type = 'log') + public static function write($msg, $type = 'log', $force = false) { // 封装日志信息 - $log[$type][] = $msg; + if (true === $force || empty(self::$config['level'])) { + $log[$type][] = $msg; + } elseif (in_array($type, self::$config['level'])) { + $log[$type][] = $msg; + } else { + return false; + } // 监听log_write Hook::listen('log_write', $log);