# @ohos.logLibrary (维测日志获å–)(系统接å£) 本模å—æ供了获å–å„类系统维测日志的能力。 > **说明:** > > - 本模å—首批接å£ä»ŽAPI version 10开始支æŒã€‚åŽç»ç‰ˆæœ¬çš„新增接å£ï¼Œé‡‡ç”¨ä¸Šè§’æ ‡å•ç‹¬æ ‡è®°æŽ¥å£çš„起始版本。 > - 本模å—为系统接å£ã€‚ ## å¯¼å…¥æ¨¡å— ```ts import { logLibrary } from '@kit.PerformanceAnalysisKit'; ``` ## LogEntry 日志文件对象接å£ã€‚ **系统能力:** SystemCapability.HiviewDFX.Hiview.LogLibrary | å称 | 类型 | å¯è¯» | å¯å†™ | 说明 | | -------- | -------- | -------- | -------- | -------- | | name | string | 是 | å¦ | 文件å称。 | | mtime | number | 是 | å¦ | 上次修改该文件的时间,表示è·1970å¹´1月1æ—¥0æ—¶0分0秒的秒数。 | | size | number | 是 | å¦ | 文件大å°ï¼Œä»¥å—节为å•ä½ã€‚ | ## logLibrary.list list(logType: string): LogEntry[] 以åŒæ¥æ–¹æ³•æŸ¥è¯¢æŒ‡å®šç±»åž‹çš„日志文件列表,接收string类型的对象作为å‚数,返回指定类型日志的文件列表信æ¯ã€‚ **需è¦æƒé™ï¼š** ohos.permission.READ_HIVIEW_SYSTEM **系统能力:** SystemCapability.HiviewDFX.Hiview.LogLibrary **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | --------- | ------------------------- | ---- | ------------------------------------------------------------ | | logType | string | 是 | 日志类型å—符串,例如“HILOGâ€, "FAULTLOG", "BETACLUB", "REMOTELOG"ç‰ã€‚ | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------------------------------------------ | | LogEntry[] | 日志文件对象的数组。 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[维测日志错误ç ](errorcode-loglibrary-sys.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | ------- | ----------------------------------------------------------------- | | 201 | Permission denied. | | 202 | Permission denied, non-system app called system api. | | 401 | Invalid argument.| **示例:** ```ts import { logLibrary } from '@kit.PerformanceAnalysisKit'; try { let logObj = logLibrary.list('HILOG'); // do something here. } catch (error) { console.error(`error code: ${error?.code}, error msg: ${error?.message}`); } ``` ## logLibrary.copy copy(logType: string, logName: string, dest: string): Promise<void> æ‹·è´æŒ‡å®šæ—¥å¿—ç±»åž‹çš„æŒ‡å®šæ–‡ä»¶åˆ°ç›®æ ‡åº”ç”¨ç›®å½•ä¸‹ã€‚ä½¿ç”¨Promise回调。 **需è¦æƒé™ï¼š** ohos.permission.READ_HIVIEW_SYSTEM **系统能力:** SystemCapability.HiviewDFX.Hiview.LogLibrary **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | --------- | ----------------------- | ---- | --------------- | | logType | string | 是 | 日志类型å—符串,例如“HILOGâ€, "FAULTLOG", "BETACLUB", "REMOTELOG"ç‰ã€‚ | | logName | string | 是 | 日志文件å称。 | | dest | string | 是 | ç›®æ ‡ç›®å½•ï¼Œéœ€å¡«å…¥ç›¸å¯¹ç›®å½•åç§°ã€‚ä¼ å…¥destå—串åŽï¼Œæ—¥å¿—文件将ä¿å˜åˆ°åº”用缓å˜è·¯å¾„下的"hiview/*dest*"文件夹,å³"../cache/hiview/*dest*"。å¯å¡«å…¥å¤šå±‚目录。<br>å¦‚æžœä¼ å…¥ç©ºå—串,将ä¿å˜åˆ°æ ¹ç›®å½•ä¸‹ï¼Œå³åº”用缓å˜è·¯å¾„下的hiview文件夹。 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------------------------------------------ | | Promise<void> | Promise实例,å¯ä»¥åœ¨å…¶then()ã€catch()方法ä¸åˆ†åˆ«å¯¹æ‹·è´æˆåŠŸã€æ‹·è´å¼‚常的回调进行处ç†ã€‚ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[维测日志错误ç ](errorcode-loglibrary-sys.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ---------------------------------------------------------------- | | 201 | Permission denied. | | 202 | Permission denied, non-system app called system api. | | 401 | Invalid argument.| | 21300001 | Source file does not exists. | **示例:** ```ts import { logLibrary } from '@kit.PerformanceAnalysisKit'; import { BusinessError } from '@kit.BasicServicesKit'; try { logLibrary.copy('HILOG', 'hiapplogcat-1.zip', '' ).then( (val) => { // do something here. } ).catch( (err: BusinessError) => { // do something here. } ) } catch (error) { console.error(`error code: ${error?.code}, error msg: ${error?.message}`); } ``` ## logLibrary.copy copy(logType: string, logName: string, dest: string, callback: AsyncCallback<void>): void æ‹·è´æŒ‡å®šæ—¥å¿—ç±»åž‹çš„æŒ‡å®šæ–‡ä»¶åˆ°ç›®æ ‡åº”ç”¨ç›®å½•ä¸‹ã€‚ä½¿ç”¨callback回调。 **需è¦æƒé™ï¼š** ohos.permission.READ_HIVIEW_SYSTEM **系统能力:** SystemCapability.HiviewDFX.Hiview.LogLibrary **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | --------- | ------------------------- | ---- | ------------------------------------------------------------ | | logType | string | 是 | 日志类型å—符串,例如“HILOGâ€, "FAULTLOG", "BETACLUB", "REMOTELOG"ç‰ã€‚ | | logName | string | 是 | 日志文件å称。 | | dest | string | 是 | ç›®æ ‡ç›®å½•ï¼Œéœ€å¡«å…¥ç›¸å¯¹ç›®å½•åç§°ã€‚ä¼ å…¥destå—串åŽï¼Œæ—¥å¿—文件将ä¿å˜åˆ°åº”用缓å˜è·¯å¾„下的"hiview/*dest*"文件夹,å³"../cache/hiview/*dest*"。å¯å¡«å…¥å¤šå±‚目录。<br>å¦‚æžœä¼ å…¥ç©ºå—串,将ä¿å˜åˆ°æ ¹ç›®å½•ä¸‹ï¼Œå³åº”用缓å˜è·¯å¾„下的hiview文件夹。 | | callback | AsyncCallback<void> | 是 | 回调函数,å¯ä»¥åœ¨å›žè°ƒå‡½æ•°ä¸å¤„ç†æŽ¥å£è¿”回值。0表示拷è´æˆåŠŸï¼Œå…¶å®ƒå€¼è¡¨ç¤ºæ‹·è´å¤±è´¥ã€‚ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[维测日志错误ç ](errorcode-loglibrary-sys.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | ------- | ----------------------------------------------------------------- | | 201 | Permission denied. | | 202 | Permission denied, non-system app called system api. | | 401 | Invalid argument.| | 21300001 | Source file does not exists. | **示例:** ```ts import { logLibrary } from '@kit.PerformanceAnalysisKit'; try { logLibrary.copy('HILOG', 'hiapplogcat-1.zip', 'dir1', (error, val) => { if (val === undefined) { // copy failed. } else { // copy success. } }); } catch (error) { console.error(`error code: ${error?.code}, error msg: ${error?.message}`); } ``` ## logLibrary.move move(logType: string, logName: string, dest: string): Promise<void> ç§»åŠ¨æŒ‡å®šæ—¥å¿—ç±»åž‹çš„æŒ‡å®šæ–‡ä»¶åˆ°ç›®æ ‡åº”ç”¨ç›®å½•ä¸‹ã€‚ä½¿ç”¨Promise回调。 **需è¦æƒé™ï¼š** ohos.permission.WRITE_HIVIEW_SYSTEM **系统能力:** SystemCapability.HiviewDFX.Hiview.LogLibrary **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | --------- | ----------------------- | ---- | --------------- | | logType | string | 是 | 日志类型å—符串,例如"FAULTLOG", "BETACLUB", "REMOTELOG"ç‰ã€‚ | | logName | string | 是 | 日志文件å称。 | | dest | string | 是 | ç›®æ ‡ç›®å½•ï¼Œéœ€å¡«å…¥ç›¸å¯¹ç›®å½•åç§°ã€‚ä¼ å…¥destå—串åŽï¼Œæ—¥å¿—文件将ä¿å˜åˆ°åº”用缓å˜è·¯å¾„下的"hiview/*dest*"文件夹,å³"../cache/hiview/*dest*"。å¯å¡«å…¥å¤šå±‚目录。<br>å¦‚æžœä¼ å…¥ç©ºå—串,将ä¿å˜åˆ°æ ¹ç›®å½•ä¸‹ï¼Œå³åº”用缓å˜è·¯å¾„下的hiview文件夹。 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------------------------------------------ | | Promise<void> | Promise实例,å¯ä»¥åœ¨å…¶then()ã€catch()方法ä¸åˆ†åˆ«å¯¹ç§»åŠ¨æˆåŠŸã€ç§»åŠ¨å¼‚常的回调进行处ç†ã€‚ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[维测日志错误ç ](errorcode-loglibrary-sys.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ---------------------------------------------------------------- | | 201 | Permission denied. | | 202 | Permission denied, non-system app called system api. | | 401 | Invalid argument.| | 21300001 | Source file does not exists. | **示例:** ```ts import { logLibrary } from '@kit.PerformanceAnalysisKit'; import { BusinessError } from '@kit.BasicServicesKit'; try { logLibrary.move('FAULTLOG', 'fault_log_test.zip', '' ).then( (val) => { // do something here. } ).catch( (err: BusinessError) => { // do something here. } ) } catch (error) { console.error(`error code: ${error?.code}, error msg: ${error?.message}`); } ``` ## logLibrary.move move(logType: string, logName: string, dest: string, callback: AsyncCallback<void>): void ç§»åŠ¨æŒ‡å®šæ—¥å¿—ç±»åž‹çš„æŒ‡å®šæ–‡ä»¶åˆ°ç›®æ ‡åº”ç”¨ç›®å½•ä¸‹ã€‚ä½¿ç”¨callback回调。 **需è¦æƒé™ï¼š** ohos.permission.WRITE_HIVIEW_SYSTEM **系统能力:** SystemCapability.HiviewDFX.Hiview.LogLibrary **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | --------- | ------------------------- | ---- | ------------------------------------------------------------ | | logType | string | 是 | 日志类型å—符串,例如“HILOGâ€, "FAULTLOG", "BETACLUB", "REMOTELOG"ç‰ã€‚ | | logName | string | 是 | 日志文件å称。 | | dest | string | 是 | ç›®æ ‡ç›®å½•ï¼Œéœ€å¡«å…¥ç›¸å¯¹ç›®å½•åç§°ã€‚ä¼ å…¥destå—串åŽï¼Œæ—¥å¿—文件将ä¿å˜åˆ°åº”用缓å˜è·¯å¾„下的"hiview/*dest*"文件夹,å³"../cache/hiview/*dest*"。å¯å¡«å…¥å¤šå±‚目录。<br>å¦‚æžœä¼ å…¥ç©ºå—串,将ä¿å˜åˆ°æ ¹ç›®å½•ä¸‹ï¼Œå³åº”用缓å˜è·¯å¾„下的hiview文件夹。 | | callback | AsyncCallback<void> | 是 | 回调函数,å¯ä»¥åœ¨å›žè°ƒå‡½æ•°ä¸å¤„ç†æŽ¥å£è¿”回值。0表示移动æˆåŠŸï¼Œå…¶å®ƒå€¼è¡¨ç¤ºç§»åŠ¨å¤±è´¥ã€‚ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[维测日志错误ç ](errorcode-loglibrary-sys.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | ------- | ----------------------------------------------------------------- | | 201 | Permission denied. | | 202 | Permission denied, non-system app called system api. | | 401 | Invalid argument.| | 21300001 | Source file does not exists. | **示例:** ```ts import { logLibrary } from '@kit.PerformanceAnalysisKit'; try { logLibrary.move('FAULTLOG', 'fault_log_test.zip', 'dir1/dir2', (error, val) => { if (val === undefined) { // move failed. } else { // move success. } }); } catch (error) { console.error(`error code: ${error?.code}, error msg: ${error?.message}`); } ``` ## logLibrary.remove remove(logType: string, logName: string): void 以åŒæ¥æ–¹æ³•åˆ 除指定日志类型的指定文件。 **需è¦æƒé™ï¼š** ohos.permission.WRITE_HIVIEW_SYSTEM **系统能力:** SystemCapability.HiviewDFX.Hiview.LogLibrary **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | --------- | ------------------------- | ---- | ------------------------------------------------------------ | | logType | string | 是 | 日志类型å—符串,例如"FAULTLOG", "BETACLUB", "REMOTELOG"ç‰ã€‚ | | logName | string | 是 | 日志文件å称。 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[维测日志错误ç ](errorcode-loglibrary-sys.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | ------- | ----------------------------------------------------------------- | | 201 | Permission denied. | | 202 | Permission denied, non-system app called system api. | | 401 | Invalid argument.| | 21300001 | Source file does not exists. | **示例:** ```ts import { logLibrary } from '@kit.PerformanceAnalysisKit'; try { logLibrary.remove('FAULTLOG', 'fault_log_test.zip'); } catch (error) { console.error(`error code: ${error?.code}, error msg: ${error?.message}`); } ```