public final class FaultLogger extends Object
Applications may become unavailable due to code defects or runtime exceptions. Such situations are considered application faults. When a fault occurs, the fault information is recorded for locating the cause and fixing the fault. Sample code for querying fault records is as follows:
Optional<FaultLogger.FaultLogQueryResult> resultOpt = FaultLogger.querySelfFaultLog(FaultLogger.FAULT_TYPE_NO_SPECIFIC, 10);
if (resultOpt.isPresent()) {
FaultLogger.FaultLogQueryResult result = resultOpt.get();
while (result.hasNext()) {
Optional<FaultLogger.FaultLogInfo> infoOpt = result.next();
infoOpt.ifPresent((info) -> {
// Obtain detailed fault information.
});
}
// Destroy the query result.
result.destroy();
}
A fault query may be time-consuming. Do not query fault records in the main thread or in performance-sensitive scenarios, for example, during application startup.FaultLogger.FaultLogInfo,
FaultLogger.FaultLogQueryResult| 限定符和类型 | 类 | 说明 |
|---|---|---|
static class |
FaultLogger.FaultLogInfo |
Represents an application fault record.
|
static class |
FaultLogger.FaultLogQueryResult |
Represents the query result of application fault records.
|
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static int |
FAULT_TYPE_APP_FREEZE |
Indicates application freezing fault records are queried.
|
static int |
FAULT_TYPE_CPP_CRASH |
Indicates that crash fault records in the C/C++ code are queried.
|
static int |
FAULT_TYPE_JAVA_CRASH |
Indicates that crash fault records in the Java code are queried.
|
static int |
FAULT_TYPE_JS_CRASH |
Indicates that crash fault records in the JavaScript code are queried.
|
static int |
FAULT_TYPE_NO_SPECIFIC |
Indicates that no fault type is specified, that is, records for all supported fault types are queried.
|
| 构造器 | 说明 |
|---|---|
FaultLogger() |
public static final int FAULT_TYPE_APP_FREEZE
querySelfFaultLog(int, int),
常量字段值public static final int FAULT_TYPE_CPP_CRASH
querySelfFaultLog(int, int),
常量字段值public static final int FAULT_TYPE_JAVA_CRASH
querySelfFaultLog(int, int),
常量字段值public static final int FAULT_TYPE_JS_CRASH
querySelfFaultLog(int, int),
常量字段值public static final int FAULT_TYPE_NO_SPECIFIC
querySelfFaultLog(int, int),
常量字段值public static Optional<FaultLogger.FaultLogQueryResult> querySelfFaultLog(int type, int maxNum)
type - Indicates the fault type, which is one of the following constants:
maxNum - Indicates the maximum number of fault records to be queried. The maximum value is 100. Any value greater than 100 will be taken as 100.null if the query fails or either input parameter is invalid.FaultLogger.FaultLogQueryResult