• Home
Name Date Size #Lines LOC

..--

entry/12-May-2024-580533

logs/12-May-2024-383268

.gitignoreD12-May-2024121 88

README.mdD12-May-20241.6 KiB8057

README_zh.mdD12-May-20241.6 KiB8761

build-profile.json5D12-May-20241.1 KiB4745

hvigorfile.jsD12-May-2024174 21

package.jsonD12-May-2024394 2019

README.md

1# Log
2
3## Introduction
4
5This sample shows how to use log APIs to print log information and save the information to the application installation directory.
6
7## APIs
8
9```
10    import logger from '@ohos/log'
11    import { LogLevel } from '@ohos/log'
12    import { Configure }  from '@ohos/log'
13```
14
15## Usage Instruction
16
171. Configure log printing parameters.
18
19```
20  Configure = {
21    cheese: {
22        types: string[],
23        filename: string
24    }
25    defaults: {
26        appenders: string,
27        level: LogLevel
28    }
29  }
30  // If types is set to file, logs are saved to the file named by filename. appenders indicates the log tag, and level indicates the lowest log level.
31```
32
332. Initialize a **logger** instance.
34
35```
36   logger.setConfigure(configure: Configure)
37   // configure indicates the parameter configuration.
38```
39
403. Print log information of the debug level.
41
42```
43   logger.debug(value)
44   // value indicates the log content.
45```
46
474. Print log information of the info level.
48
49```
50   logger.info(value)
51   // value indicates the log content.
52```
53
545. Print log information of the warn level.
55
56```
57   logger.warn(value)
58   // value indicates the log content.
59```
60
616. Print log information of the error level.
62
63```
64   logger.error(value)
65   // value indicates the log content.
66```
67
687. Print log information of the fatal level.
69
70```
71   logger.fatal(value, bool)
72   // value indicates the log content.
73```
74
75## Constraints
76
771. This sample requires API version 8 or later.
78
792. This sample requires DevEco Studio 3.0 Beta4 (Build Version: 3.0.0.992, built on July 14, 2022) to compile and run.
80

README_zh.md

1# 日志打印
2
3### 简介
4
5提供日志打印类,并将日志信息保存至应用安装目录下。
6
7### 相关概念
8
9日志打印:hilog日志系统,使应用/服务可以按照指定级别、标识和格式字符串输出日志内容,帮助开发者了解应用/服务的运行状态,更好地调试程序。
10
11### 相关权限
12
13不涉及。
14
15##### 导入接口
16
17```
18    import logger from '@ohos/log'
19    import { LogLevel } from '@ohos/log'
20    import { Configure }  from '@ohos/log'
21```
22
23##### 接口说明
24
251. configure参数设置
26
27```
28  Configure = {
29    cheese: {
30        types: string[],
31        filename: string
32    }
33    defaults: {
34        appenders: string,
35        level: LogLevel
36    }
37  }
38  //types为file时将日志输出保存到以filename参数命名的文件中;appenders为日志打印tag;level为打印日志文件的最低等级
39```
40
412. logger类初始化
42
43```
44   logger.setConfigure(configure: Configure)
45   //configure为配置参数
46```
47
483. debug类型打印日志
49
50```
51   logger.debug(value)
52   //value为打印日志内容
53```
54
554. info类型打印日志
56
57```
58   logger.info(value)
59   //value为打印日志内容
60```
61
625. warn类型打印日志
63
64```
65   logger.warn(value)
66   //value为打印日志内容
67```
68
696. error类型打印日志
70
71```
72   logger.error(value)
73   //value为打印日志内容
74```
75
767. fatal类型打印日志
77
78```
79   logger.fatal(value, bool)
80   //value为打印日志内容
81```
82
83### 兼容性
84
851.本示例支持 OpenHarmony API version 8 及以上版本。
86
872.本示例需要使用DevEco Studio 3.0 Beta4 (Build Version: 3.0.0.992, built on July 14, 2022)才可编译运行。