From 927c075f297318d8e50c20954b6c85925b775421 Mon Sep 17 00:00:00 2001 From: jinchun Date: Tue, 2 Feb 2016 20:02:37 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=89=E4=BF=AE=E6=AD=A3notice=20=E7=9A=84?= =?UTF-8?q?=E6=8B=BC=E5=86=99=E9=94=99=E8=AF=AF=EF=BC=9B2=EF=BC=89?= =?UTF-8?q?=E8=8B=B1=E6=96=87=E7=9A=84":"=E5=90=8E=E9=9D=A2=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E4=B8=AA=E7=A9=BA=E6=A0=BC=EF=BC=9B3=EF=BC=89?= =?UTF-8?q?=E8=A1=A5=E5=85=A8Log::send()=20=E6=B3=A8=E9=87=8A=EF=BC=9B4?= =?UTF-8?q?=EF=BC=89=E5=88=A0=E9=99=A4Error.php=20=E9=87=8C=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E7=9A=84=20key=EF=BC=9B5=EF=BC=89=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20File=20Log=20=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Error.php | 4 +-- library/think/Loader.php | 4 +-- library/think/Log.php | 19 ++++++----- library/think/log/driver/Socket.php | 2 +- library/think/log/driver/Trace.php | 2 +- .../library/think/log/driver/.gitignore | 2 -- .../library/think/log/driver/fileTest.php | 34 +++++++++++++++++++ 7 files changed, 49 insertions(+), 18 deletions(-) delete mode 100644 tests/thinkphp/library/think/log/driver/.gitignore create mode 100644 tests/thinkphp/library/think/log/driver/fileTest.php diff --git a/library/think/Error.php b/library/think/Error.php index 218d6710..e7c96c45 100644 --- a/library/think/Error.php +++ b/library/think/Error.php @@ -93,7 +93,7 @@ class Error { if ($errno & Config::get('exception_ignore_type')) { // 忽略的异常记录到日志 - Log::record("[{$errno}]{$errstr}[{$errfile}:{$errline}]", 'notic'); + Log::record("[{$errno}]{$errstr}[{$errfile}:{$errline}]", 'notice'); } else { // 将错误信息托管至 think\exception\ErrorException throw new ErrorException($errno, $errstr, $errfile, $errline, $errcontext); @@ -268,8 +268,6 @@ class Error 'DS' => defined('DS') ? DS : 'undefined', '__INFO__' => defined('__INFO__') ? __INFO__ : 'undefined', '__EXT__' => defined('__EXT__') ? __EXT__ : 'undefined', - '__INFO__' => defined('__INFO__') ? __INFO__ : 'undefined', - '__EXT__' => defined('__EXT__') ? __EXT__ : 'undefined', ]; } } diff --git a/library/think/Loader.php b/library/think/Loader.php index 07731367..9e0183ee 100644 --- a/library/think/Loader.php +++ b/library/think/Loader.php @@ -71,7 +71,7 @@ class Loader APP_DEBUG && self::$load[] = $filename; include $filename; } else { - Log::record('autoloader error : ' . $filename, 'notic'); + Log::record('autoloader error : ' . $filename, 'notice'); } } } @@ -294,7 +294,7 @@ class Loader if (class_exists($class)) { $model = new $class($name); } else { - Log::record('实例化不存在的类:' . $class, 'notic'); + Log::record('实例化不存在的类:' . $class, 'notice'); $model = new Model($name); } } diff --git a/library/think/Log.php b/library/think/Log.php index aaecfbf2..cf7c13a8 100644 --- a/library/think/Log.php +++ b/library/think/Log.php @@ -13,17 +13,17 @@ namespace think; class Log { - const LOG = 'log'; - const ERROR = 'error'; - const INFO = 'info'; - const SQL = 'sql'; - const NOTIC = 'notic'; - const ALERT = 'alert'; + const LOG = 'log'; + const ERROR = 'error'; + const INFO = 'info'; + const SQL = 'sql'; + const NOTICE = 'notice'; + const ALERT = 'alert'; // 日志信息 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; // 通知发送驱动 @@ -37,7 +37,7 @@ class Log unset($config['type']); 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']); 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 */ public static function send($msg) diff --git a/library/think/log/driver/Socket.php b/library/think/log/driver/Socket.php index 6ee6ddac..25d27f5e 100644 --- a/library/think/log/driver/Socket.php +++ b/library/think/log/driver/Socket.php @@ -94,7 +94,7 @@ class Socket ]; 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'; } } diff --git a/library/think/log/driver/Trace.php b/library/think/log/driver/Trace.php index d1b02c9c..7cc3c182 100644 --- a/library/think/log/driver/Trace.php +++ b/library/think/log/driver/Trace.php @@ -15,7 +15,7 @@ namespace think\log\driver; */ 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 = [ 'trace_file' => '', ]; diff --git a/tests/thinkphp/library/think/log/driver/.gitignore b/tests/thinkphp/library/think/log/driver/.gitignore deleted file mode 100644 index a3a0c8b5..00000000 --- a/tests/thinkphp/library/think/log/driver/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore \ No newline at end of file diff --git a/tests/thinkphp/library/think/log/driver/fileTest.php b/tests/thinkphp/library/think/log/driver/fileTest.php new file mode 100644 index 00000000..168ef81a --- /dev/null +++ b/tests/thinkphp/library/think/log/driver/fileTest.php @@ -0,0 +1,34 @@ + +// +---------------------------------------------------------------------- + +/** + * 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)); + } +}