diff --git a/zh-cn/application-dev/reference/apis/js-apis-loglibrary.md b/zh-cn/application-dev/reference/apis/js-apis-loglibrary.md new file mode 100644 index 0000000000000000000000000000000000000000..7d85d0d1dd92c9211c3ca6bdcc59dba0a7714114 --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-loglibrary.md @@ -0,0 +1,319 @@ +# @ohos.logLibrary (维测日志获取) + +本模块提供了获取各类系统维测日志的能力。 + +> **说明:** +> +> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +> - 本模块的接口为系统接口。 + +## 导入模块 + +```js +import logLibrary from '@ohos.logLibrary'; +``` + +## 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[] | 日志文件对象的数组。 | + +**错误码:** + +以下错误码的详细介绍请参见[维测日志错误码](../errorcodes/errorcode-loglibrary.md)。 + +| 错误码ID | 错误信息 | +| ------- | ----------------------------------------------------------------- | +| 201 | Permission denied. | +| 202 | Permission denied, non-system app called system api. | +| 401 | Invalid argument.| + +**示例:** + +```js +import logLibrary from '@ohos.logLibrary'; + +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*"。可填入多层目录。
如果传入空字串,将保存到根目录下,即应用缓存路径下的hiview文件夹。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------- | ------------------------------------------------------------ | +| Promise<void> | Promise实例,可以在其then()、catch()方法中分别对拷贝成功、拷贝异常的回调进行处理。 | + +**错误码:** + +以下错误码的详细介绍请参见[维测日志错误码](../errorcodes/errorcode-loglibrary.md)。 + +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------------------------------- | +| 201 | Permission denied. | +| 202 | Permission denied, non-system app called system api. | +| 401 | Invalid argument.| +| 21300001 | Source file does not exists. | + +**示例:** + +```js +import logLibrary from '@ohos.logLibrary'; + +try { + logLibrary.copy('HILOG', 'hiapplogcat-1.zip', '' + ).then( + (val) => { + // do something here. + } + ).catch( + (err) => { + // 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*"。可填入多层目录。
如果传入空字串,将保存到根目录下,即应用缓存路径下的hiview文件夹。 | +| callback | AsyncCallback<void> | 是 | 回调函数,可以在回调函数中处理接口返回值。0表示拷贝成功,其它值表示拷贝失败。 | + +**错误码:** + +以下错误码的详细介绍请参见[维测日志错误码](../errorcodes/errorcode-loglibrary.md)。 + +| 错误码ID | 错误信息 | +| ------- | ----------------------------------------------------------------- | +| 201 | Permission denied. | +| 202 | Permission denied, non-system app called system api. | +| 401 | Invalid argument.| +| 21300001 | Source file does not exists. | + +**示例:** + +```js +import logLibrary from '@ohos.logLibrary'; + +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*"。可填入多层目录。
如果传入空字串,将保存到根目录下,即应用缓存路径下的hiview文件夹。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------- | ------------------------------------------------------------ | +| Promise<void> | Promise实例,可以在其then()、catch()方法中分别对移动成功、移动异常的回调进行处理。 | + +**错误码:** + +以下错误码的详细介绍请参见[维测日志错误码](../errorcodes/errorcode-loglibrary.md)。 + +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------------------------------- | +| 201 | Permission denied. | +| 202 | Permission denied, non-system app called system api. | +| 401 | Invalid argument.| +| 21300001 | Source file does not exists. | + +**示例:** + +```js +import logLibrary from '@ohos.logLibrary'; + +try { + logLibrary.move('FAULTLOG', 'fault_log_test.zip', '' + ).then( + (val) => { + // do something here. + } + ).catch( + (err) => { + // 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*"。可填入多层目录。
如果传入空字串,将保存到根目录下,即应用缓存路径下的hiview文件夹。 | +| callback | AsyncCallback<void> | 是 | 回调函数,可以在回调函数中处理接口返回值。0表示移动成功,其它值表示移动失败。 | + +**错误码:** + +以下错误码的详细介绍请参见[维测日志错误码](../errorcodes/errorcode-loglibrary.md)。 + +| 错误码ID | 错误信息 | +| ------- | ----------------------------------------------------------------- | +| 201 | Permission denied. | +| 202 | Permission denied, non-system app called system api. | +| 401 | Invalid argument.| +| 21300001 | Source file does not exists. | + +**示例:** + +```js +import logLibrary from '@ohos.logLibrary'; + +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 | 是 | 日志文件名称。 | + +**错误码:** + +以下错误码的详细介绍请参见[维测日志错误码](../errorcodes/errorcode-loglibrary.md)。 + +| 错误码ID | 错误信息 | +| ------- | ----------------------------------------------------------------- | +| 201 | Permission denied. | +| 202 | Permission denied, non-system app called system api. | +| 401 | Invalid argument.| +| 21300001 | Source file does not exists. | + +**示例:** + +```js +import logLibrary from '@ohos.logLibrary'; + +try { + logLibrary.remove('FAULTLOG', 'fault_log_test.zip'); +} catch (error) { + console.error(`error code: ${error.code}, error msg: ${error.message}`); +} +``` \ No newline at end of file diff --git a/zh-cn/application-dev/reference/errorcodes/errorcode-loglibrary.md b/zh-cn/application-dev/reference/errorcodes/errorcode-loglibrary.md new file mode 100644 index 0000000000000000000000000000000000000000..004d3375c4f5ac41ec153d4b16b8b9ea00294b0a --- /dev/null +++ b/zh-cn/application-dev/reference/errorcodes/errorcode-loglibrary.md @@ -0,0 +1,24 @@ +# 维测日志错误码 + +> **说明:** +> +> 以下仅介绍本模块特有错误码,通用错误码请参考[通用错误码说明文档](errorcode-universal.md)。 + +## 21300001 指定文件不存在 + +**错误信息** + +The specified file does not exist. + +**错误描述** + +在调用拷贝、移动、删除接口进行文件操作时,指定类型日志中不存在指定文件名的文件。 + +**可能原因** + +1.文件名称传递错误。 +2.传入的文件名在物理设备上不存在。 + +**处理步骤** + +检查传入的文件名称是否正确。