public function save(array $log = [])
{
if (!$this->check()) {
return false;
}
$runtime = number_format(microtime(true) - THINK_START_TIME, 10);
$reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞';
$time_str = ' [运行时间:' . number_format($runtime, 6) . 's][吞吐率:' . $reqs . 'req/s]';
$memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
$memory_str = ' [内存消耗:' . $memory_use . 'kb]';
$file_load = ' [文件加载:' . count(get_included_files()) . ']';
if (isset($_SERVER['HTTP_HOST'])) {
$current_uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
} else {
$current_uri = 'cmd:' . implode(' ', $_SERVER['argv']);
}
// 基本信息
$trace[] = ['type' => 'group', 'msg' => $current_uri . $time_str . $memory_str . $file_load, 'css' => $this->css['page']];
foreach ($log as $type => $val) {
$trace[] = ['type' => 'groupCollapsed', 'msg' => '[ ' . $type . ' ]', 'css' => isset($this->css[$type]) ? $this->css[$type] : ''];
foreach ($val as $msg) {
if (!is_string($msg)) {
$msg = var_export($msg, true);
}
$trace[] = ['type' => 'log', 'msg' => $msg, 'css' => ''];
}
$trace[] = ['type' => 'groupEnd', 'msg' => '', 'css' => ''];
}
if ($this->config['show_included_files']) {
$trace[] = ['type' => 'groupCollapsed', 'msg' => '[ file ]', 'css' => ''];
$trace[] = ['type' => 'log', 'msg' => implode("\n", get_included_files()), 'css' => ''];
$trace[] = ['type' => 'groupEnd', 'msg' => '', 'css' => ''];
}
$trace[] = ['type' => 'groupEnd', 'msg' => '', 'css' => ''];
$tabid = $this->getClientArg('tabid');
if (!($client_id = $this->getClientArg('client_id'))) {
$client_id = '';
}
if (!empty($this->allowForceClientIds)) {
//强制推送到多个client_id
foreach ($this->allowForceClientIds as $force_client_id) {
$client_id = $force_client_id;
$this->sendToClient($tabid, $client_id, $trace, $force_client_id);
}
} else {
$this->sendToClient($tabid, $client_id, $trace, '');
}
return true;
}