Index 控制器
~~~
<?php
namespace app\index\controller;
use think\Log;
class Index
{
/**
* log 常規日志,用于記錄日志
* error 錯誤,一般會導致程序的終止
* notice 警告,程序可以運行但是還不夠完美的錯誤
* info 信息,程序輸出信息
* debug 調試,用于調試信息
*/
public function log()
{
Log::log('常規日志信息');
Log::info('程序輸出信息');
Log::notice('警告信息');
Log::error('導致程序終止的錯誤信息');
}
}
~~~
Mysql日志驅動(extend目錄)
~~~
<?php
namespace log;
/**
* 日志類-Mysql
*/
class Mysql
{
// 實例化并傳入參數
public function __construct($config = [])
{
}
/**
* 日志寫入接口
* @access public
* @param array $log 日志信息
* @return bool
*/
public function save(array $log = [])
{
dump($log);
return true;
}
}
~~~
運行
~~~
http://localhost/workspace/DragonApi/public/index.php/index/index/log
~~~
`log`方法的腳本運行完之后,將會自動調用日志類-`Mysql`的 `save` 方法。
~~~
array(4) {
["log"] => array(1) {
[0] => string(18) "常規日志信息"
}
["info"] => array(1) {
[0] => string(18) "程序輸出信息"
}
["notice"] => array(1) {
[0] => string(12) "警告信息"
}
["error"] => array(1) {
[0] => string(33) "導致程序終止的錯誤信息"
}
}
~~~