From 7676ebadd99b7a234f9a7c6dc3819dd802f5f01b Mon Sep 17 00:00:00 2001 From: wenlong_12 Date: Tue, 5 Sep 2023 22:26:11 +0800 Subject: [PATCH] modify faultlogger src from js to ArkTs Signed-off-by: wenlong_12 Change-Id: I6d37fe382e87d77d2eceb474f053b30aa0f0f8ad --- .../reference/apis/js-apis-faultLogger.md | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-faultLogger.md b/zh-cn/application-dev/reference/apis/js-apis-faultLogger.md index c403de289f..de5fc12b3f 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-faultLogger.md +++ b/zh-cn/application-dev/reference/apis/js-apis-faultLogger.md @@ -6,7 +6,7 @@ ## 导入模块 -```js +```ts import faultLogger from '@ohos.faultLogger' ``` @@ -65,13 +65,16 @@ query(faultType: FaultType, callback: AsyncCallback<Array<FaultLogInfo> **示例:** -```js -function queryFaultLogCallback(error, value) { +```ts +import faultLogger from '@ohos.faultLogger' +import { BusinessError } from '@ohos.base' + +function queryFaultLogCallback(error: BusinessError, value: Array) { if (error) { console.info('error is ' + error); } else { console.info("value length is " + value.length); - let len = value.length; + let len: number = value.length; for (let i = 0; i < len; i++) { console.info("log: " + i); console.info("Log pid: " + value[i].pid); @@ -88,7 +91,7 @@ function queryFaultLogCallback(error, value) { try { faultLogger.query(faultLogger.FaultType.JS_CRASH, queryFaultLogCallback); } catch (err) { - console.error(`code: ${err.code}, message: ${err.message}`); + console.error(`code: ${(err as BusinessError).code}, message: ${(err as BusinessError).message}`); } ``` @@ -122,13 +125,16 @@ query(faultType: FaultType) : Promise<Array<FaultLogInfo>> **示例:** -```js +```ts +import faultLogger from '@ohos.faultLogger' +import { BusinessError } from '@ohos.base' + async function getLog() { try { - let value = await faultLogger.query(faultLogger.FaultType.JS_CRASH); + let value: Array = await faultLogger.query(faultLogger.FaultType.JS_CRASH); if (value) { console.info("value length is " + value.length); - let len = value.length; + let len: number = value.length; for (let i = 0; i < len; i++) { console.info("log: " + i); console.info("Log pid: " + value[i].pid); @@ -142,7 +148,7 @@ async function getLog() { } } } catch (err) { - console.error(`code: ${err.code}, message: ${err.message}`); + console.error(`code: ${(err as BusinessError).code}, message: ${(err as BusinessError).message}`); } } ``` @@ -168,13 +174,16 @@ querySelfFaultLog(faultType: FaultType, callback: AsyncCallback<Array<Faul **示例:** -```js -function queryFaultLogCallback(error, value) { +```ts +import faultLogger from '@ohos.faultLogger' +import { BusinessError } from '@ohos.base' + +function queryFaultLogCallback(error: BusinessError, value: Array) { if (error) { console.info('error is ' + error); } else { console.info("value length is " + value.length); - let len = value.length; + let len: number = value.length; for (let i = 0; i < len; i++) { console.info("log: " + i); console.info("Log pid: " + value[i].pid); @@ -217,12 +226,14 @@ querySelfFaultLog(faultType: FaultType) : Promise<Array<FaultLogInfo>&g **示例:** -```js +```ts +import faultLogger from '@ohos.faultLogger' + async function getLog() { - let value = await faultLogger.querySelfFaultLog(faultLogger.FaultType.JS_CRASH); + let value: Array = await faultLogger.querySelfFaultLog(faultLogger.FaultType.JS_CRASH); if (value) { console.info("value length is " + value.length); - let len = value.length; + let len: number = value.length; for (let i = 0; i < len; i++) { console.info("log: " + i); console.info("Log pid: " + value[i].pid); -- GitLab