未验证 提交 c4545c26 编写于 作者: O openharmony_ci 提交者: Gitee

!11691 翻译已完成:10708 faultlogger新增异常处理机制

Merge pull request !11691 from wusongqing/TR10708
......@@ -39,10 +39,12 @@ Defines the data structure of the fault log information.
| summary | string | Summary of the fault.|
| fullLog | string | Full log text.|
## faultLogger.querySelfFaultLog
## faultLogger.querySelfFaultLog<sup>(deprecated)</sup>
querySelfFaultLog(faultType: FaultType, callback: AsyncCallback&lt;Array&lt;FaultLogInfo&gt;&gt;) : void
> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [faultLogger.query](#faultloggerquery9) instead.
Obtains the fault information about the current process. This API uses an asynchronous callback to return the fault information array obtained, which contains a maximum of 10 pieces of fault information.
**System capability**: SystemCapability.HiviewDFX.Hiview.FaultLogger
......@@ -52,7 +54,8 @@ Obtains the fault information about the current process. This API uses an asynch
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| faultType | [FaultType](#faulttype) | Yes| Fault type.|
| callback | AsyncCallbackArray&lt;Array&lt;[FaultLogInfo](#faultloginfo)>> | Yes | Callback used to return the fault information array.<br/>The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval. In this case, an error string will be returned. |
| callback | AsyncCallbackArray&lt;Array&lt;[FaultLogInfo](#faultloginfo)&gt;&gt; | Yes| Callback used to return the fault information array.<br>The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval. In this case, an error string will be returned.
**Example**
```js
......@@ -78,10 +81,12 @@ function queryFaultLogCallback(error, value) {
faultLogger.querySelfFaultLog(faultLogger.FaultType.JS_CRASH, queryFaultLogCallback);
```
## faultLogger.querySelfFaultLog
## faultLogger.querySelfFaultLog<sup>(deprecated)</sup>
querySelfFaultLog(faultType: FaultType) : Promise&lt;Array&lt;FaultLogInfo&gt;&gt;
> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [faultLogger.query](#faultloggerquery9-1) instead.
Obtains the fault information about the current process. This API uses a promise to return the fault information array obtained, which contains a maximum of 10 pieces of fault information.
**System capability**: SystemCapability.HiviewDFX.Hiview.FaultLogger
......@@ -105,18 +110,125 @@ async function getLog() {
let value = await faultLogger.querySelfFaultLog(faultLogger.FaultType.JS_CRASH);
if (value) {
console.info("value length is " + value.length);
let len = value.length;
for (let i = 0; i < len; i++) {
console.info("log: " + i);
console.info("Log pid: " + value[i].pid);
console.info("Log uid: " + value[i].uid);
console.info("Log type: " + value[i].type);
console.info("Log timestamp: " + value[i].timestamp);
console.info("Log reason: " + value[i].reason);
console.info("Log module: " + value[i].module);
console.info("Log summary: " + value[i].summary);
console.info("Log text: " + value[i].fullLog);
}
let len = value.length;
for (let i = 0; i < len; i++) {
console.info("log: " + i);
console.info("Log pid: " + value[i].pid);
console.info("Log uid: " + value[i].uid);
console.info("Log type: " + value[i].type);
console.info("Log timestamp: " + value[i].timestamp);
console.info("Log reason: " + value[i].reason);
console.info("Log module: " + value[i].module);
console.info("Log summary: " + value[i].summary);
console.info("Log text: " + value[i].fullLog);
}
}
}
```
## faultLogger.query<sup>9+</sup>
query(faultType: FaultType, callback: AsyncCallback&lt;Array&lt;FaultLogInfo&gt;&gt;) : void
Obtains the fault information about the current process. This API uses an asynchronous callback to return the fault information array obtained, which contains a maximum of 10 pieces of fault information.
**System capability**: SystemCapability.HiviewDFX.Hiview.FaultLogger
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| faultType | [FaultType](#faulttype) | Yes| Fault type.|
| callback | AsyncCallbackArray&lt;Array&lt;[FaultLogInfo](#faultloginfo)&gt;&gt; | Yes| Callback used to return the fault information array.<br>The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval. In this case, an error string will be returned.
**Error codes**
For details about the error codes, see [faultLogger Error Codes](../errorcodes/errorcode-faultlogger.md).
| ID| Error Message|
| --- | --- |
| 10600001 | The service is not running or broken |
**Example**
```js
function queryFaultLogCallback(error, value) {
if (error) {
console.info('error is ' + error);
} else {
console.info("value length is " + value.length);
let len = value.length;
for (let i = 0; i < len; i++) {
console.info("log: " + i);
console.info("Log pid: " + value[i].pid);
console.info("Log uid: " + value[i].uid);
console.info("Log type: " + value[i].type);
console.info("Log timestamp: " + value[i].timestamp);
console.info("Log reason: " + value[i].reason);
console.info("Log module: " + value[i].module);
console.info("Log summary: " + value[i].summary);
console.info("Log text: " + value[i].fullLog);
}
}
}
try {
faultLogger.query(faultLogger.FaultType.JS_CRASH, queryFaultLogCallback);
} catch (err) {
console.error(`code: ${err.code}, message: ${err.message}`);
}
```
## faultLogger.query<sup>9+</sup>
query(faultType: FaultType) : Promise&lt;Array&lt;FaultLogInfo&gt;&gt;
Obtains the fault information about the current process. This API uses a promise to return the fault information array obtained, which contains a maximum of 10 pieces of fault information.
**System capability**: SystemCapability.HiviewDFX.Hiview.FaultLogger
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| faultType | [FaultType](#faulttype) | Yes| Fault type.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;Array&lt;[FaultLogInfo](#faultloginfo)&gt;&gt; | Promise used to return the fault information array. You can obtain the fault information instance in its **then()** method or use **await**.<br>The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval.|
**Error codes**
For details about the error codes, see [faultLogger Error Codes](../errorcodes/errorcode-faultlogger.md).
| ID| Error Message|
| --- | --- |
| 10600001 | The service is not running or broken |
**Example**
```js
async function getLog() {
try {
let value = await faultLogger.query(faultLogger.FaultType.JS_CRASH);
if (value) {
console.info("value length is " + value.length);
let len = value.length;
for (let i = 0; i < len; i++) {
console.info("log: " + i);
console.info("Log pid: " + value[i].pid);
console.info("Log uid: " + value[i].uid);
console.info("Log type: " + value[i].type);
console.info("Log timestamp: " + value[i].timestamp);
console.info("Log reason: " + value[i].reason);
console.info("Log module: " + value[i].module);
console.info("Log summary: " + value[i].summary);
console.info("Log text: " + value[i].fullLog);
}
}
} catch (err) {
console.error(`code: ${err.code}, message: ${err.message}`);
}
}
```
# faultLogger Error Codes
## 10600001 Service Faulty or Not Started
**Error Message**
The service is not running or broken.
**Description**
This error code is reported when the service is not started or is faulty.
**Possible Causes**
The hiview service is not started.
**Solution**
Retry the operation.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册