mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
1)修正notice 的拼写错误;2)英文的":"后面加了个空格;3)补全Log::send() 注释;4)删除Error.php 里重复的 key;5)添加 File Log 测试用例
This commit is contained in:
@@ -93,7 +93,7 @@ class Error
|
|||||||
{
|
{
|
||||||
if ($errno & Config::get('exception_ignore_type')) {
|
if ($errno & Config::get('exception_ignore_type')) {
|
||||||
// 忽略的异常记录到日志
|
// 忽略的异常记录到日志
|
||||||
Log::record("[{$errno}]{$errstr}[{$errfile}:{$errline}]", 'notic');
|
Log::record("[{$errno}]{$errstr}[{$errfile}:{$errline}]", 'notice');
|
||||||
} else {
|
} else {
|
||||||
// 将错误信息托管至 think\exception\ErrorException
|
// 将错误信息托管至 think\exception\ErrorException
|
||||||
throw new ErrorException($errno, $errstr, $errfile, $errline, $errcontext);
|
throw new ErrorException($errno, $errstr, $errfile, $errline, $errcontext);
|
||||||
@@ -268,8 +268,6 @@ class Error
|
|||||||
'DS' => defined('DS') ? DS : 'undefined',
|
'DS' => defined('DS') ? DS : 'undefined',
|
||||||
'__INFO__' => defined('__INFO__') ? __INFO__ : 'undefined',
|
'__INFO__' => defined('__INFO__') ? __INFO__ : 'undefined',
|
||||||
'__EXT__' => defined('__EXT__') ? __EXT__ : 'undefined',
|
'__EXT__' => defined('__EXT__') ? __EXT__ : 'undefined',
|
||||||
'__INFO__' => defined('__INFO__') ? __INFO__ : 'undefined',
|
|
||||||
'__EXT__' => defined('__EXT__') ? __EXT__ : 'undefined',
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class Loader
|
|||||||
APP_DEBUG && self::$load[] = $filename;
|
APP_DEBUG && self::$load[] = $filename;
|
||||||
include $filename;
|
include $filename;
|
||||||
} else {
|
} else {
|
||||||
Log::record('autoloader error : ' . $filename, 'notic');
|
Log::record('autoloader error : ' . $filename, 'notice');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -294,7 +294,7 @@ class Loader
|
|||||||
if (class_exists($class)) {
|
if (class_exists($class)) {
|
||||||
$model = new $class($name);
|
$model = new $class($name);
|
||||||
} else {
|
} else {
|
||||||
Log::record('实例化不存在的类:' . $class, 'notic');
|
Log::record('实例化不存在的类:' . $class, 'notice');
|
||||||
$model = new Model($name);
|
$model = new Model($name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,17 +13,17 @@ namespace think;
|
|||||||
|
|
||||||
class Log
|
class Log
|
||||||
{
|
{
|
||||||
const LOG = 'log';
|
const LOG = 'log';
|
||||||
const ERROR = 'error';
|
const ERROR = 'error';
|
||||||
const INFO = 'info';
|
const INFO = 'info';
|
||||||
const SQL = 'sql';
|
const SQL = 'sql';
|
||||||
const NOTIC = 'notic';
|
const NOTICE = 'notice';
|
||||||
const ALERT = 'alert';
|
const ALERT = 'alert';
|
||||||
|
|
||||||
// 日志信息
|
// 日志信息
|
||||||
protected static $log = [];
|
protected static $log = [];
|
||||||
// 日志类型
|
// 日志类型
|
||||||
protected static $type = ['log', 'error', 'info', 'sql', 'notic', 'alert'];
|
protected static $type = ['log', 'error', 'info', 'sql', 'notice', 'alert'];
|
||||||
// 日志写入驱动
|
// 日志写入驱动
|
||||||
protected static $driver = null;
|
protected static $driver = null;
|
||||||
// 通知发送驱动
|
// 通知发送驱动
|
||||||
@@ -37,7 +37,7 @@ class Log
|
|||||||
unset($config['type']);
|
unset($config['type']);
|
||||||
self::$driver = new $class($config);
|
self::$driver = new $class($config);
|
||||||
// 记录初始化信息
|
// 记录初始化信息
|
||||||
APP_DEBUG && Log::record('[ LOG ] INIT ' . $type . ':' . var_export($config, true), 'info');
|
APP_DEBUG && Log::record('[ LOG ] INIT ' . $type . ': ' . var_export($config, true), 'info');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通知初始化
|
// 通知初始化
|
||||||
@@ -48,7 +48,7 @@ class Log
|
|||||||
unset($config['type']);
|
unset($config['type']);
|
||||||
self::$alarm = new $class($config['alarm']);
|
self::$alarm = new $class($config['alarm']);
|
||||||
// 记录初始化信息
|
// 记录初始化信息
|
||||||
APP_DEBUG && Log::record('[ CACHE ] ALARM ' . $type . ':' . var_export($config, true), 'info');
|
APP_DEBUG && Log::record('[ CACHE ] ALARM ' . $type . ': ' . var_export($config, true), 'info');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,6 +111,7 @@ class Log
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送预警通知
|
* 发送预警通知
|
||||||
|
* @param mixed $msg 调试信息
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function send($msg)
|
public static function send($msg)
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ class Socket
|
|||||||
];
|
];
|
||||||
|
|
||||||
foreach ($logs as &$log) {
|
foreach ($logs as &$log) {
|
||||||
if (in_array($log['type'], ['sql', 'notic', 'debug', 'info'])) {
|
if (in_array($log['type'], ['sql', 'notice', 'debug', 'info'])) {
|
||||||
$log['type'] = 'log';
|
$log['type'] = 'log';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace think\log\driver;
|
|||||||
*/
|
*/
|
||||||
class Trace
|
class Trace
|
||||||
{
|
{
|
||||||
protected $tabs = ['base' => '基本', 'file' => '文件', 'info' => '流程', 'notic|error' => '错误', 'sql' => 'SQL', 'debug|log' => '调试'];
|
protected $tabs = ['base' => '基本', 'file' => '文件', 'info' => '流程', 'notice|error' => '错误', 'sql' => 'SQL', 'debug|log' => '调试'];
|
||||||
protected $config = [
|
protected $config = [
|
||||||
'trace_file' => '',
|
'trace_file' => '',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
*
|
|
||||||
!.gitignore
|
|
||||||
34
tests/thinkphp/library/think/log/driver/fileTest.php
Normal file
34
tests/thinkphp/library/think/log/driver/fileTest.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test File Log
|
||||||
|
*/
|
||||||
|
namespace tests\thinkphp\library\think\log\driver;
|
||||||
|
|
||||||
|
use think\Log;
|
||||||
|
|
||||||
|
class fileTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
Log::init(['type' => 'file']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRecord()
|
||||||
|
{
|
||||||
|
$record_msg = 'record';
|
||||||
|
Log::record($record_msg, 'notice');
|
||||||
|
$logs = Log::getLog();
|
||||||
|
|
||||||
|
$this->assertNotFalse(array_search(['type' => 'notice', 'msg' => $record_msg], $logs));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user