OpenHarmony ArkTS 框架下打印日志,两个地方需要处理一下:

1,解除开发板日志限流命令:

        (1) hdc_std shell param set hilog.flowctrl.proc.on false
        (2) hdc_std shell hilog -Q pidoff
        (3) hdc_std shell hilog -p off
        (4) hdc_std shell hilog -b D

2,日志过长,分段打印

printAllMsg(tag: string, msg: string, isFirstPrint:boolean=true,eachPrintLength:number=900) {
  if (isFirstPrint) {
    console.info(tag+ 'msg print start-->')
  }

  if (msg && msg.length <= eachPrintLength) {
    console.info(tag+ msg);
    console.info(tag+ 'msg print end');
  } else if (msg && msg.length > eachPrintLength) {
    console.info(tag+msg.substr(0, eachPrintLength));
    console.info(tag+'msg print next-->:');
    let nextMsg: string = msg.substr(eachPrintLength, msg.length)
    printAllMsg(tag, nextMsg, false)
  } else {
    console.info(tag+ ':msg is undefined');
  }
}

      

Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐