1# log.h 2 3 4## Overview 5 6Defines the logging functions of the HiLog module. 7 8Before outputting logs, you must define the service domain, and log tag, use the function with the specified log type and level, and specify the privacy identifier. 9 10Service domain: service domain of logs. You can define the value as required. Its value is a hexadecimal integer ranging from 0x0 to 0xFFFF. 11 12**Log tag**: a string used to identify the class, file, or service behavior. 13 14**Log level**: DEBUG, INFO, WARN, ERROR, or FATAL. 15 16**Parameter format**: printf format string, which starts with a % character, including a parameter type identifier and a variable parameter. 17 18**Privacy identifier**: **{public}** or **{private}** added between the % character and the parameter type identifier in each parameter. 19 20 If no privacy identifier is added, the parameter is considered to be **private**. 21 22Example 23 24Define the service domain and tag: 25 26``` 27#define LOG_DOMAIN 0x0201 28#define LOG_TAG "MY_TAG" 29``` 30 31Print the log: 32 33``` 34HILOG_WARN(LOG_APP, "Failed to visit %{private}s, reason:%{public}d.", url, errno); 35``` 36 37Output: 38 39``` 4005-06 15:01:06.870 1051 1051 W 0201/MY_TAG: Failed to visit <private>, reason:503. 41``` 42 43**File to include**: <hilog/log.h> 44 45**Since**: 8 46 47**Related module**: [HiLog](_hi_log.md) 48 49 50## Summary 51 52 53### Macros 54 55| Name| Description| 56| -------- | -------- | 57| [LOG_DOMAIN](_hi_log.md#log_domain) 0 | Defines the service domain for a log file.| 58| [LOG_TAG](_hi_log.md#log_tag) NULL | Defines a string constant used to identify the class, file, or service.| 59| [OH_LOG_DEBUG](_hi_log.md#oh_log_debug)(type, ...) ((void)[OH_LOG_Print](_hi_log.md#oh_log_print)((type), [LOG_DEBUG](_hi_log.md), [LOG_DOMAIN](_hi_log.md#log_domain), [LOG_TAG](_hi_log.md#log_tag), \_\_VA_ARGS\_\_)) | Outputs DEBUG logs. This is a function-like macro.| 60| [OH_LOG_INFO](_hi_log.md#oh_log_info)(type, ...) ((void)[OH_LOG_Print](_hi_log.md#oh_log_print)((type), [LOG_INFO](_hi_log.md), [LOG_DOMAIN](_hi_log.md#log_domain), [LOG_TAG](_hi_log.md#log_tag), \_\_VA_ARGS\_\_)) | Outputs INFO logs. This is a function-like macro.| 61| [OH_LOG_WARN](_hi_log.md#oh_log_warn)(type, ...) ((void)[OH_LOG_Print](_hi_log.md#oh_log_print)((type), [LOG_WARN](_hi_log.md), [LOG_DOMAIN](_hi_log.md#log_domain), [LOG_TAG](_hi_log.md#log_tag), \_\_VA_ARGS\_\_)) | Outputs WARN logs. This is a function-like macro.| 62| [OH_LOG_ERROR](_hi_log.md#oh_log_error)(type, ...) ((void)[OH_LOG_Print](_hi_log.md#oh_log_print)((type), [LOG_ERROR](_hi_log.md), [LOG_DOMAIN](_hi_log.md#log_domain), [LOG_TAG](_hi_log.md#log_tag), \_\_VA_ARGS\_\_)) | Outputs ERROR logs. This is a function-like macro.| 63| [OH_LOG_FATAL](_hi_log.md#oh_log_fatal)(type, ...) ((void)HiLogPrint((type), [LOG_FATAL](_hi_log.md), [LOG_DOMAIN](_hi_log.md#log_domain), [LOG_TAG](_hi_log.md#log_tag), \_\_VA_ARGS\_\_)) | Outputs FATAL logs. This is a function-like macro.| 64 65 66### Types 67 68| Name| Description| 69| -------- | -------- | 70| typedef void(\* [LogCallback](_hi_log.md#logcallback)) (const [LogType](_hi_log.md#logtype) type, const [LogLevel](_hi_log.md#loglevel) level, const unsigned int domain, const char \*tag, const char \*msg) | Pointer to the callback function. You can customize the processing of logs in the callback.| 71 72 73### Enums 74 75| Name| Description| 76| -------- | -------- | 77| [LogType](_hi_log.md#logtype) { [LOG_APP](_hi_log.md) = 0 } | Log type.| 78| [LogLevel](_hi_log.md#loglevel) {<br>LOG_DEBUG = 3, LOG_INFO = 4, LOG_WARN = 5, LOG_ERROR = 6, LOG_FATAL = 7<br>} | Log level.| 79 80 81### Functions 82 83| Name| Description| 84| -------- | -------- | 85| int [OH_LOG_Print](_hi_log.md#oh_log_print) ([LogType](_hi_log.md#logtype) type, [LogLevel](_hi_log.md#loglevel) level, unsigned int domain, const char \*tag, const char \*fmt,...) \_\_attribute__((\_\_format__(os_log | Whether to output logs.| 86| int bool [OH_LOG_IsLoggable](_hi_log.md#oh_log_isloggable) (unsigned int domain, const char \*tag, [LogLevel](_hi_log.md#loglevel) level) | Whether logs of the specified service domain, tag, and level can be printed.| 87| void [OH_LOG_SetCallback](_hi_log.md#oh_log_setcallback) ([LogCallback](_hi_log.md#logcallback) callback) | Registered callback function.| 88