// 把 $fileLogger 放到全局日志列表中 unset($fileLogger); /* * **************** 如果是调试模式,在这里设置调试 ************************ */ if ($f3->get('DEBUG')) { // 调试模式,关闭缓存 $f3->set('CACHE', false); // 调试模式下,弄一个 fileLogger 方便查看所有的日志输出 $fileLogger = new \Core\Log\File(\Core\Helper\Utility\Time::localTimeStr('Y-m-d') . '.mobile.debug.log'); $logger->addLogger($fileLogger); // 把 smarty 的一些错误警告关闭,不然会影响我们的调试 Smarty::muteExpectedErrors(); // 使用自定义的调试框架 if ($f3->get('USERDEBUG')) { require_once PROTECTED_PATH . '/Framework/Debug/BzfDebug.php'; // 开启 debug 功能 BzfDebug::enableDebug(); } // 启动网页调试,让我们的调试信息直接显示在网页的下方,见 smarty_helper 中的使用 $logCollector = new \Core\Log\Collector(); $logger->addLogger($logCollector); // 把 $logCollector 放到 全局的 logger 中 } else { /*** 错误处理,如果网站出现错误,我简单的把用户定位到 首页 ***/ $f3->set('ONERROR', function ($f3) { /** * Information about the last HTTP error that occurred. * ERROR.code is the HTTP status code. * ERROR.title contains a brief description of the error. * ERROR.text provides greater detail. For HTTP 500 errors, use ERROR.trace to retrieve the stack trace. */ $code = $f3->get('ERROR.code');
$fileLogger = new \Core\Log\File('install.log'); $logger->addLogger($fileLogger); unset($fileLogger); /* * **************** 如果是调试模式,在这里设置调试 ************************ */ if ($f3->get('DEBUG')) { // 调试模式,关闭缓存 $f3->set('CACHE', false); // 把 smarty 的一些错误警告关闭,不然会影响我们的调试 Smarty::muteExpectedErrors(); // 使用自定义的调试框架 if ($f3->get('USERDEBUG')) { require_once PROTECTED_PATH . '/Framework/Debug/BzfDebug.php'; // 开启 debug 功能 BzfDebug::enableDebug(); // 开启 Smarty Web Log BzfDebug::enableSmartyWebLog(); } } // ---------------------------------------- 4. 设置工程环境 -------------------------------------- // 设置代码路径 \Core\Plugin\SystemHelper::addAutoloadPath(INSTALL_PATH . '/Code', true); // 设置路由,这样用户就能访问到我们的程序了 $f3->config(INSTALL_PATH . '/route.cfg'); // 增加 smarty 模板搜索路径 $smarty->addTemplateDir(INSTALL_PATH . '/Tpl/'); // 加载 smarty 的扩展,里面有一些我们需要用到的函数 require_once INSTALL_PATH . '/Code/smarty_helper.php'; // 注册 smarty 函数 smarty_helper_register($smarty); // ---------------------------------------- 5. 为 JavaScript 设置变量 -------------------------------------- // 设置网站的 Base 路径,给 JavaScript 使用
public static function smartyLogOutputFilter($source, Smarty_Internal_Template $smartyTemplate) { global $smarty; $currentController = $smarty->getTemplateVars('currentController'); // 如果不是 htmlController,我们不加 weblog ,以防破坏文件结构 // 比如你输出的是 xml, json,如果加了 weblog 你的文件就会出现解析错误 if ($currentController && $currentController instanceof \Core\Controller\BaseController && !$currentController->isHtmlController()) { return $source; } $header = <<<EOF <!-- 调试信息 --> <style> #dfwloetw_log_table, #dfwloetw_log_table tr, #dfwloetw_log_table th, #dfwloetw_log_table tbody tr td { \ttext-align:left; \tbackground-color:white; \tborder: 2px solid gray; \tcolor:black; \tfont-size:16px; \tpadding:0px 5px; } #dfwloetw_log_table tbody tr td.breakword { \tword-wrap:break-word; \tword-break:break-all; } </style> <table id="dfwloetw_log_table" width="100%" > \t<thead> \t\t<tr> \t\t <th>Id</th> \t\t\t<th>Level</th> \t\t\t<th>Source</th> \t\t\t<th>Message</th> \t\t</tr> \t</thead> \t<tbody> EOF; $footer = <<<EOF \t</tbody> </table><!-- /调试信息 --> EOF; $logCollector = BzfDebug::startDebugLogCollector(); $logMsgArray = $logCollector->getLogArray(); $content = ''; $index = 0; foreach ($logMsgArray as $info) { $content .= '<tr><td>' . $index++ . '</td><td>' . htmlentities($info['level']) . '</td><td>' . htmlentities($info['source']) . '</td><td class="breakword">' . htmlentities($info['msg']) . '</td></tr>'; } return $source . $header . $content . $footer; }