1e41f4b71Sopenharmony_ci# log.h 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## Overview 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ciDefines the logging functions of the HiLog module. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ciBefore 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. 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ciService domain: service domain of logs. You can define the value as required. Its value is a hexadecimal integer ranging from 0x0 to 0xFFFF. 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci**Log tag**: a string used to identify the class, file, or service behavior. 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci**Log level**: DEBUG, INFO, WARN, ERROR, or FATAL. 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci**Parameter format**: printf format string, which starts with a % character, including a parameter type identifier and a variable parameter. 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci**Privacy identifier**: **{public}** or **{private}** added between the % character and the parameter type identifier in each parameter. 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ciIf no privacy identifier is added, the parameter is considered to be **private**. 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ciExample 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ciDefine the service domain and tag: 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci``` 27e41f4b71Sopenharmony_ci#define LOG_DOMAIN 0x0201 28e41f4b71Sopenharmony_ci#define LOG_TAG "MY_TAG" 29e41f4b71Sopenharmony_ci``` 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ciPrint the log: 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci``` 34e41f4b71Sopenharmony_ciHILOG_WARN(LOG_APP, "Failed to visit %{private}s, reason:%{public}d.", url, errno); 35e41f4b71Sopenharmony_ci``` 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ciOutput: 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci``` 40e41f4b71Sopenharmony_ci05-06 15:01:06.870 1051 1051 W 0201/MY_TAG: Failed to visit <private>, reason:503. 41e41f4b71Sopenharmony_ci``` 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci**Since**: 8 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci**Related module**: [HiLog](_hi_log.md) 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci## Summary 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci### Macros 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci| Name| Description| 54e41f4b71Sopenharmony_ci| -------- | -------- | 55e41f4b71Sopenharmony_ci| [LOG_DOMAIN](_hi_log.md#log_domain) 0 | Defines the service domain for a log file.| 56e41f4b71Sopenharmony_ci| [LOG_TAG](_hi_log.md#log_tag) NULL | Defines a string constant used to identify the class, file, or service.| 57e41f4b71Sopenharmony_ci| [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.| 58e41f4b71Sopenharmony_ci| [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.| 59e41f4b71Sopenharmony_ci| [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.| 60e41f4b71Sopenharmony_ci| [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.| 61e41f4b71Sopenharmony_ci| [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.| 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci### Types 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci| Name| Description| 67e41f4b71Sopenharmony_ci| -------- | -------- | 68e41f4b71Sopenharmony_ci| 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.| 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci### Enums 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci| Name| Description| 74e41f4b71Sopenharmony_ci| -------- | -------- | 75e41f4b71Sopenharmony_ci| [LogType](_hi_log.md#logtype) { [LOG_APP](_hi_log.md) = 0 } | Log type.| 76e41f4b71Sopenharmony_ci| [LogLevel](_hi_log.md#loglevel) {<br>LOG_DEBUG = 3, LOG_INFO = 4, LOG_WARN = 5, LOG_ERROR = 6, LOG_FATAL = 7<br>} | Log level.| 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci### Functions 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci| Name| Description| 82e41f4b71Sopenharmony_ci| -------- | -------- | 83e41f4b71Sopenharmony_ci| 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.| 84e41f4b71Sopenharmony_ci| 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.| 85e41f4b71Sopenharmony_ci| void [OH_LOG_SetCallback](_hi_log.md#oh_log_setcallback) ([LogCallback](_hi_log.md#logcallback) callback) | Registered callback function.| 86