config = array_merge($this->config, $config); } } /** * 落盘一批日志(扁平 array). * * 镜像 DebugMysql.save 的遍历方式(type 作 level、message 作 content、 * 非字符串 message 转 print_r),但落盘动作换为 DebugLogToolkit: * 全部行拼接成一个多行字符串后只调一次 appendLine(单次 flock 批量写入); * 行间以 \n 连接、行尾 \n 由 appendLine 统一补齐,避免双换行。 * 整体 catch \Throwable 后仍返回 true——日志失败绝不反噬业务。 * * @param array $log Channel save() 传入的扁平 LogRecord 数组 */ public function save(array $log): bool { try { $lines = []; foreach ($log as $log_item) { if (!is_object($log_item) || !isset($log_item->type) || !is_string($log_item->type) || !isset($log_item->message)) { continue; } $content = $log_item->message; if (!is_string($content)) { $content = print_r($content, true); } $row = DebugLogToolkit::buildRow($log_item->type, $content); $lines[] = DebugLogToolkit::encodeRow($row); } if (!empty($lines)) { DebugLogToolkit::appendLine(implode("\n", $lines)); } } catch (\Throwable $th) { // 铁律:绝不抛异常、绝不返回 false(失败即静默丢弃本批日志) } return true; } }