logJson static method

void logJson(
  1. dynamic obj, {
  2. bool prettyPrint = true,
})

以日志方式输出 JSON 字符串(支持缩进)。

原方法名 printJson 踩 CLAUDE.md 日志禁词(print),故重命名为 logJson。 printJson 已保留为 deprecated 别名以避免下游硬断裂。

Implementation

static void logJson(dynamic obj, {bool prettyPrint = true}) {
  try {
    if (prettyPrint) {
      const encoder = JsonEncoder.withIndent('  ');
      logger.i(encoder.convert(obj));
    } else {
      logger.i(json.encode(obj));
    }
  } catch (e) {
    logger.e('JSON 打印失败: $e');
  }
}