ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
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) "导致程序终止的错误信息" } } ~~~