# @ohos.faultLogger (故障日志获å–) > **说明:** > > 本模å—首批接å£ä»ŽAPI version 8开始支æŒã€‚åŽç»ç‰ˆæœ¬çš„æ–°å¢žæŽ¥å£ï¼Œé‡‡ç”¨ä¸Šè§’æ ‡å•ç‹¬æ ‡è®°æŽ¥å£çš„起始版本。 ## å¯¼å…¥æ¨¡å— ```ts import { FaultLogger } from '@kit.PerformanceAnalysisKit'; ``` ## FaultType 故障类型枚举。 **系统能力:** SystemCapability.HiviewDFX.Hiview.FaultLogger | åç§° | 值 | 说明 | | -------- | -------- | -------- | | NO_SPECIFIC | 0 | ä¸åŒºåˆ†æ•…障类型 | | CPP_CRASH | 2 | C++ç¨‹åºæ•…障类型 | | JS_CRASH | 3 | JSç¨‹åºæ•…障类型 | | APP_FREEZE | 4 | 应用程åºå¡æ»æ•…障类型 | ## FaultLogInfo æ•…éšœä¿¡æ¯æ•°æ®ç»“构,获å–到的故障信æ¯çš„æ•°æ®ç»“构。 **系统能力:** SystemCapability.HiviewDFX.Hiview.FaultLogger | åç§° | 类型 | å¿…å¡« | 说明 | | -------- | -------- | -------- | -------- | | pid | number | 是 | 故障进程的进程id | | uid | number | 是 | 故障进程的用户id | | type | [FaultType](#faulttype) | 是 | 故障类型 | | timestamp | number | 是 | æ—¥å¿—ç”Ÿæˆæ—¶çš„æ¯«ç§’级时间戳 | | reason | string | 是 | å‘ç”Ÿæ•…éšœçš„åŽŸå› | | module | string | 是 | å‘ç”Ÿæ•…éšœçš„æ¨¡å— | | summary | string | 是 | æ•…éšœçš„æ¦‚è¦ | | fullLog | string | 是 | 故障日志全文 | ## FaultLogger.query<sup>9+</sup> query(faultType: FaultType, callback: AsyncCallback<Array<FaultLogInfo>>) : void 获å–当å‰è¿›ç¨‹æ•…障信æ¯ï¼Œè¯¥æ–¹æ³•通过回调方å¼èŽ·å–æ•…éšœä¿¡æ¯æ•°ç»„ï¼Œæ•…éšœä¿¡æ¯æ•°ç»„内最多上报10份故障信æ¯ã€‚ **系统能力:** SystemCapability.HiviewDFX.Hiview.FaultLogger **傿•°ï¼š** | 傿•°å | 类型 | å¿…å¡« | 说明 | | -------- | -------- | -------- | -------- | | faultType | [FaultType](#faulttype) | 是 | è¾“å…¥è¦æŸ¥è¯¢çš„æ•…障类型。 | | callback | AsyncCallback<Array<[FaultLogInfo](#faultloginfo)>> | 是 | 回调函数,在回调函数ä¸èŽ·å–æ•…éšœä¿¡æ¯æ•°ç»„。<br/>- valueæ‹¿åˆ°æ•…éšœä¿¡æ¯æ•°ç»„ï¼›value为undefined表示获å–过程ä¸å‡ºçŽ°å¼‚å¸¸ï¼Œerror返回错误æç¤ºå—符串 **错误ç :** 以下错误ç 的详细介ç»å‚è§[faultLogger错误ç ](errorcode-faultlogger.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | --- | --- | | 401 | The parameter check failed, Parameter type error | | 801 | The specified SystemCapability name was not found | | 10600001 | The service is not started or is faulty | **示例:** ```ts import { FaultLogger } from '@kit.PerformanceAnalysisKit'; import { BusinessError } from '@kit.BasicServicesKit'; function queryFaultLogCallback(error: BusinessError, value: Array<FaultLogger.FaultLogInfo>) { if (error) { console.info('error is ' + error); } else { console.info("value length is " + 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); 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 as BusinessError).code}, message: ${(err as BusinessError).message}`); } ``` ## FaultLogger.query<sup>9+</sup> query(faultType: FaultType) : Promise<Array<FaultLogInfo>> 获å–当å‰è¿›ç¨‹æ•…障信æ¯ï¼Œè¯¥æ–¹æ³•通过Promiseæ–¹å¼è¿”å›žæ•…éšœä¿¡æ¯æ•°ç»„ï¼Œæ•…éšœä¿¡æ¯æ•°ç»„内最多上报10份故障信æ¯ã€‚ **系统能力:** SystemCapability.HiviewDFX.Hiview.FaultLogger **傿•°ï¼š** | 傿•°å | 类型 | å¿…å¡« | 说明 | | -------- | -------- | -------- | -------- | | faultType | [FaultType](#faulttype) | 是 | è¾“å…¥è¦æŸ¥è¯¢çš„æ•…障类型。 | **返回值:** | 类型 | 说明 | | -------- | -------- | | Promise<Array<[FaultLogInfo](#faultloginfo)>> | Promise实例,å¯ä»¥åœ¨å…¶then()方法ä¸èŽ·å–æ•…障信æ¯å®žä¾‹ï¼Œä¹Ÿå¯ä»¥ä½¿ç”¨await。 <br/>- valueæ‹¿åˆ°æ•…éšœä¿¡æ¯æ•°ç»„ï¼›value为undefined表示获å–过程ä¸å‡ºçް异叏 | **错误ç :** 以下错误ç 的详细介ç»å‚è§[faultLogger错误ç ](errorcode-faultlogger.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | --- | --- | | 401 | The parameter check failed, Parameter type error | | 801 | The specified SystemCapability name was not found | | 10600001 | The service is not started or is faulty | **示例:** ```ts import { FaultLogger } from '@kit.PerformanceAnalysisKit'; import { BusinessError } from '@kit.BasicServicesKit'; async function getLog() { try { let value: Array<FaultLogger.FaultLogInfo> = await FaultLogger.query(FaultLogger.FaultType.JS_CRASH); if (value) { console.info("value length is " + 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); 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 as BusinessError).code}, message: ${(err as BusinessError).message}`); } } ``` ## FaultLogger.querySelfFaultLog<sup>(deprecated)</sup> querySelfFaultLog(faultType: FaultType, callback: AsyncCallback<Array<FaultLogInfo>>) : void > **说明:** > > 从 API Version 9 开始废弃,建议使用[FaultLogger.query](#faultloggerquery9)替代。 获å–当å‰è¿›ç¨‹æ•…障信æ¯ï¼Œè¯¥æ–¹æ³•通过回调方å¼èŽ·å–æ•…éšœä¿¡æ¯æ•°ç»„ï¼Œæ•…éšœä¿¡æ¯æ•°ç»„内最多上报10份故障信æ¯ã€‚ **系统能力:** SystemCapability.HiviewDFX.Hiview.FaultLogger **傿•°ï¼š** | 傿•°å | 类型 | å¿…å¡« | 说明 | | -------- | -------- | -------- | -------- | | faultType | [FaultType](#faulttype) | 是 | è¾“å…¥è¦æŸ¥è¯¢çš„æ•…障类型。 | | callback | AsyncCallback<Array<[FaultLogInfo](#faultloginfo)>> | 是 | 回调函数,在回调函数ä¸èŽ·å–æ•…éšœä¿¡æ¯æ•°ç»„。<br/>- valueæ‹¿åˆ°æ•…éšœä¿¡æ¯æ•°ç»„ï¼›value为undefined表示获å–过程ä¸å‡ºçŽ°å¼‚å¸¸ï¼Œerror返回错误æç¤ºå—符串 **示例:** ```ts import { FaultLogger } from '@kit.PerformanceAnalysisKit'; import { BusinessError } from '@kit.BasicServicesKit'; function queryFaultLogCallback(error: BusinessError, value: Array<FaultLogger.FaultLogInfo>) { if (error) { console.info('error is ' + error); } else { console.info("value length is " + 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); 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.querySelfFaultLog(FaultLogger.FaultType.JS_CRASH, queryFaultLogCallback); ``` ## FaultLogger.querySelfFaultLog<sup>(deprecated)</sup> querySelfFaultLog(faultType: FaultType) : Promise<Array<FaultLogInfo>> > **说明:** > > 从 API Version 9 开始废弃,建议使用[FaultLogger.query](#faultloggerquery9-1)替代。 获å–当å‰è¿›ç¨‹æ•…障信æ¯ï¼Œè¯¥æ–¹æ³•通过Promiseæ–¹å¼è¿”å›žæ•…éšœä¿¡æ¯æ•°ç»„ï¼Œæ•…éšœä¿¡æ¯æ•°ç»„内最多上报10份故障信æ¯ã€‚ **系统能力:** SystemCapability.HiviewDFX.Hiview.FaultLogger **傿•°ï¼š** | 傿•°å | 类型 | å¿…å¡« | 说明 | | -------- | -------- | -------- | -------- | | faultType | [FaultType](#faulttype) | 是 | è¾“å…¥è¦æŸ¥è¯¢çš„æ•…障类型。 | **返回值:** | 类型 | 说明 | | -------- | -------- | | Promise<Array<[FaultLogInfo](#faultloginfo)>> | Promise实例,å¯ä»¥åœ¨å…¶then()方法ä¸èŽ·å–æ•…障信æ¯å®žä¾‹ï¼Œä¹Ÿå¯ä»¥ä½¿ç”¨await。 <br/>- valueæ‹¿åˆ°æ•…éšœä¿¡æ¯æ•°ç»„ï¼›value为undefined表示获å–过程ä¸å‡ºçް异叏 | **示例:** ```ts import { FaultLogger } from '@kit.PerformanceAnalysisKit'; async function getLog() { let value: Array<FaultLogger.FaultLogInfo> = await FaultLogger.querySelfFaultLog(FaultLogger.FaultType.JS_CRASH); if (value) { console.info("value length is " + 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); 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); } } } ```