添加日志允许记录级别功能

This commit is contained in:
thinkphp
2016-07-04 18:20:07 +08:00
parent ca243c3e14
commit 81ff60592a
2 changed files with 27 additions and 5 deletions

View File

@@ -148,6 +148,8 @@ return [
'type' => 'File',
// 日志保存目录
'path' => LOG_PATH,
// 日志记录级别
'level' => [],
],
// +----------------------------------------------------------------------

View File

@@ -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)
{
// 封装日志信息
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);