1e41f4b71Sopenharmony_ci# HiLog 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## Overview 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ciProvides logging functions. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ciFor example, you can use logging functions to output logs of the specified log type, service domain, log tag, and log level. 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiLog 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci**Since**: 8 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## Summary 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci### File 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci| Name| Description| 21e41f4b71Sopenharmony_ci| -------- | -------- | 22e41f4b71Sopenharmony_ci| [log.h](log_8h.md) | Defines the logging functions of the HiLog module.<br>**File to include**: <hilog/log.h><br>**Library**: libhilog_ndk.z.so| 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci### Macros 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci| Name| Description| 28e41f4b71Sopenharmony_ci| -------- | -------- | 29e41f4b71Sopenharmony_ci| [LOG_DOMAIN](#log_domain) 0 | Defines the service domain for a log file.| 30e41f4b71Sopenharmony_ci| [LOG_TAG](#log_tag) NULL | Defines a string constant used to identify the class, file, or service.| 31e41f4b71Sopenharmony_ci| [OH_LOG_DEBUG](#oh_log_debug)(type, ...) ((void)[OH_LOG_Print](#oh_log_print)((type), LOG_DEBUG, [LOG_DOMAIN](#log_domain), [LOG_TAG](#log_tag), \_\_VA_ARGS\_\_)) | Outputs DEBUG logs. This is a function-like macro.| 32e41f4b71Sopenharmony_ci| [OH_LOG_INFO](#oh_log_info)(type, ...) ((void)[OH_LOG_Print](#oh_log_print)((type), LOG_INFO, [LOG_DOMAIN](#log_domain), [LOG_TAG](#log_tag), \_\_VA_ARGS\_\_)) | Outputs INFO logs. This is a function-like macro.| 33e41f4b71Sopenharmony_ci| [OH_LOG_WARN](#oh_log_warn)(type, ...) ((void)[OH_LOG_Print](#oh_log_print)((type), LOG_WARN, [LOG_DOMAIN](#log_domain), [LOG_TAG](#log_tag), \_\_VA_ARGS\_\_)) | Outputs WARN logs. This is a function-like macro.| 34e41f4b71Sopenharmony_ci| [OH_LOG_ERROR](#oh_log_error)(type, ...) ((void)[OH_LOG_Print](#oh_log_print)((type), LOG_ERROR, [LOG_DOMAIN](#log_domain), [LOG_TAG](#log_tag), \_\_VA_ARGS\_\_)) | Outputs ERROR logs. This is a function-like macro.| 35e41f4b71Sopenharmony_ci| [OH_LOG_FATAL](#oh_log_fatal)(type, ...) ((void)HiLogPrint((type), LOG_FATAL, [LOG_DOMAIN](#log_domain), [LOG_TAG](#log_tag), \_\_VA_ARGS\_\_)) | Outputs FATAL logs. This is a function-like macro.| 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci### Types 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci| Name| Description| 41e41f4b71Sopenharmony_ci| -------- | -------- | 42e41f4b71Sopenharmony_ci| typedef void(\* [LogCallback](#logcallback)) (const [LogType](#logtype) type, const [LogLevel](#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.| 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci### Enum 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci| Name| Description| 48e41f4b71Sopenharmony_ci| -------- | -------- | 49e41f4b71Sopenharmony_ci| [LogType](#logtype) { LOG_APP = 0 } | **Log Type**| 50e41f4b71Sopenharmony_ci| [LogLevel](#loglevel) {<br>LOG_DEBUG = 3,<br>LOG_INFO = 4,<br>LOG_WARN = 5,<br>LOG_ERROR = 6,<br>LOG_FATAL = 7<br>} | Log level.| 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci### Functions 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci| Name| Description| 56e41f4b71Sopenharmony_ci| -------- | -------- | 57e41f4b71Sopenharmony_ci| int [OH_LOG_Print](#oh_log_print) ([LogType](#logtype) type, [LogLevel](#loglevel) level, unsigned int domain, const char \*tag, const char \*fmt,...) \_\_attribute\_\_((\_\_format\_\_(os_log | Outputs logs.| 58e41f4b71Sopenharmony_ci| int bool [OH_LOG_IsLoggable](#oh_log_isloggable) (unsigned int domain, const char \*tag, [LogLevel](#loglevel) level) | Checks whether logs of the specified service domain, tag, and level can be printed.| 59e41f4b71Sopenharmony_ci| void [OH_LOG_SetCallback](#oh_log_setcallback) ([LogCallback](#logcallback) callback) | Registers a callback function.| 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci## Macro Description 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci### LOG_DOMAIN 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci``` 68e41f4b71Sopenharmony_ci#define LOG_DOMAIN 0 69e41f4b71Sopenharmony_ci``` 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci**Description** 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ciDefines the service domain for a log file. 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ciThe service domain is used to identify the subsystem and module of a service. Its value is a hexadecimal integer ranging from 0x0 to 0xFFFF. If the value is beyond the range, its significant bits are automatically truncated. 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci**Since**: 8 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci### LOG_TAG 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci``` 83e41f4b71Sopenharmony_ci#define LOG_TAG NULL 84e41f4b71Sopenharmony_ci``` 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci**Description** 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ciDefines a string constant used to identify the class, file, or service. 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci**Since**: 8 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci### OH_LOG_DEBUG 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci``` 96e41f4b71Sopenharmony_ci#define OH_LOG_DEBUG( type, ... ) ((void)OH_LOG_Print((type), LOG_DEBUG, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 97e41f4b71Sopenharmony_ci``` 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci**Description** 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ciOutputs DEBUG logs. This is a function-like macro. 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ciBefore calling this function, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file. 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci**Since**: 8 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci**Parameters** 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci| Name| Description| 110e41f4b71Sopenharmony_ci| -------- | -------- | 111e41f4b71Sopenharmony_ci| type | Log type. The type for third-party applications is defined by **LOG_APP**.| 112e41f4b71Sopenharmony_ci| fmt | Format string, which is an enhancement of a printf format string and supports the privacy identifier. Specifically, **{public}** or **{private}** is added between the % character and the format specifier in each parameter.| 113e41f4b71Sopenharmony_ci| ... | Parameter list corresponding to the parameter type in the format string. The number and type of parameters must be mapped onto the identifier in the format string.| 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci**See** 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci[OH_LOG_Print](#oh_log_print) 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci### OH_LOG_ERROR 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci``` 123e41f4b71Sopenharmony_ci#define OH_LOG_ERROR( type, ... ) ((void)OH_LOG_Print((type), LOG_ERROR, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 124e41f4b71Sopenharmony_ci``` 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci**Description** 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ciOutputs ERROR logs. This is a function-like macro. 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ciBefore calling this function, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file. 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci**Since**: 8 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci**Parameters** 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci| Name| Description| 137e41f4b71Sopenharmony_ci| -------- | -------- | 138e41f4b71Sopenharmony_ci| type | Log type. The type for third-party applications is defined by **LOG_APP**.| 139e41f4b71Sopenharmony_ci| fmt | Format string, which is an enhancement of a printf format string and supports the privacy identifier. Specifically, **{public}** or **{private}** is added between the % character and the format specifier in each parameter.| 140e41f4b71Sopenharmony_ci| ... | Parameter list corresponding to the parameter type in the format string. The number and type of parameters must be mapped onto the identifier in the format string.| 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci**See** 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci[OH_LOG_Print](#oh_log_print) 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci### OH_LOG_FATAL 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci``` 150e41f4b71Sopenharmony_ci#define OH_LOG_FATAL( type, ... ) ((void)HiLogPrint((type), LOG_FATAL, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 151e41f4b71Sopenharmony_ci``` 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci**Description** 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ciOutputs FATAL logs. This is a function-like macro. 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ciBefore calling this function, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file. 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci**Since**: 8 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci**Parameters** 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci| Name| Description| 164e41f4b71Sopenharmony_ci| -------- | -------- | 165e41f4b71Sopenharmony_ci| type | Log type. The type for third-party applications is defined by **LOG_APP**.| 166e41f4b71Sopenharmony_ci| fmt | Format string, which is an enhancement of a printf format string and supports the privacy identifier. Specifically, **{public}** or **{private}** is added between the % character and the format specifier in each parameter.| 167e41f4b71Sopenharmony_ci| ... | Parameter list corresponding to the parameter type in the format string. The number and type of parameters must be mapped onto the identifier in the format string.| 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ci**See** 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci[OH_LOG_Print](#oh_log_print) 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci### OH_LOG_INFO 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci``` 177e41f4b71Sopenharmony_ci#define OH_LOG_INFO( type, ... ) ((void)OH_LOG_Print((type), LOG_INFO, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 178e41f4b71Sopenharmony_ci``` 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci**Description** 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ciOutputs INFO logs. This is a function-like macro. 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ciBefore calling this function, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file. 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci**Since**: 8 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci**Parameters** 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci| Name| Description| 191e41f4b71Sopenharmony_ci| -------- | -------- | 192e41f4b71Sopenharmony_ci| type | Log type. The type for third-party applications is defined by **LOG_APP**.| 193e41f4b71Sopenharmony_ci| fmt | Format string, which is an enhancement of a printf format string and supports the privacy identifier. Specifically, **{public}** or **{private}** is added between the % character and the format specifier in each parameter.| 194e41f4b71Sopenharmony_ci| ... | Parameter list corresponding to the parameter type in the format string. The number and type of parameters must be mapped onto the identifier in the format string.| 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci**See** 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci[OH_LOG_Print](#oh_log_print) 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci### OH_LOG_WARN 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ci``` 204e41f4b71Sopenharmony_ci#define OH_LOG_WARN( type, ... ) ((void)OH_LOG_Print((type), LOG_WARN, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 205e41f4b71Sopenharmony_ci``` 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci**Description** 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ciOutputs WARN logs. This is a function-like macro. 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ciBefore calling this function, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file. 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci**Since**: 8 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci**Parameters** 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci| Name| Description| 218e41f4b71Sopenharmony_ci| -------- | -------- | 219e41f4b71Sopenharmony_ci| type | Log type. The type for third-party applications is defined by **LOG_APP**.| 220e41f4b71Sopenharmony_ci| fmt | Format string, which is an enhancement of a printf format string and supports the privacy identifier. Specifically, **{public}** or **{private}** is added between the % character and the format specifier in each parameter.| 221e41f4b71Sopenharmony_ci| ... | Parameter list corresponding to the parameter type in the format string. The number and type of parameters must be mapped onto the identifier in the format string.| 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci**See** 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci[OH_LOG_Print](#oh_log_print) 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci## Type Description 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci### LogCallback 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci``` 234e41f4b71Sopenharmony_citypedef void(* LogCallback) (const LogType type, const LogLevel level, const unsigned int domain, const char *tag, const char *msg) 235e41f4b71Sopenharmony_ci``` 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_ci**Description** 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ciPointer to the callback function. You can customize the processing of logs in the callback. 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ci**Since**: 11 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ci**Parameters** 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_ci| Name| Description| 246e41f4b71Sopenharmony_ci| -------- | -------- | 247e41f4b71Sopenharmony_ci| type | Log type. The type for third-party applications is defined by **LOG_APP**.| 248e41f4b71Sopenharmony_ci| level | Log level. The value can be **LOG_DEBUG**, **LOG_INFO**, **LOG_WARN**, **LOG_ERROR**, and **LOG_FATAL**.| 249e41f4b71Sopenharmony_ci| domain | Service domain. Its value is a hexadecimal integer ranging from 0x0 to 0xFFFF.| 250e41f4b71Sopenharmony_ci| tag | Log tag, which is a string used to identify the class, file, or service.| 251e41f4b71Sopenharmony_ci| msg | Log content, which is made up of formatted log strings.| 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci## Enum Description 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci### LogLevel 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ci``` 260e41f4b71Sopenharmony_cienum LogLevel 261e41f4b71Sopenharmony_ci``` 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ci**Description** 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ciLog level. 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ciYou are advised to select log levels based on their respective use cases. Log levels: 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ci**DEBUG**: provides more detailed process information than INFO logs to help developers analyze service processes and locate faults. DEBUG logs are not recorded in official versions by default. They are available in debug versions or in official versions with the debug function enabled. 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci**INFO**: indicates the key service process nodes and exceptions (for example, no network signal or login failure) that occur during service running. These logs should be recorded by the dominant module in the service to avoid repeated logging conducted by multiple invoked modules or low-level functions. 272e41f4b71Sopenharmony_ci 273e41f4b71Sopenharmony_ci**WARN**: indicates a severe, unexpected fault that has little impact on users and can be rectified by the programs themselves or through simple operations. 274e41f4b71Sopenharmony_ci 275e41f4b71Sopenharmony_ci**ERROR**: indicates a program or functional error that affects the normal running or use of the functionality and can be fixed at a high cost, for example, by resetting data. 276e41f4b71Sopenharmony_ci 277e41f4b71Sopenharmony_ci**FATAL**: indicates that a program or functionality is about to crash and the fault cannot be rectified. 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci**Since**: 8 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ci| Value| Description| 282e41f4b71Sopenharmony_ci| -------- | -------- | 283e41f4b71Sopenharmony_ci| LOG_DEBUG | DEBUG level to be used by **OH_LOG_DEBUG**.| 284e41f4b71Sopenharmony_ci| LOG_INFO | INFO level to be used by **OH_LOG_INFO**.| 285e41f4b71Sopenharmony_ci| LOG_WARN | WARN level to be used by **OH_LOG_WARN**.| 286e41f4b71Sopenharmony_ci| LOG_ERROR | ERROR level to be used by **OH_LOG_ERROR**.| 287e41f4b71Sopenharmony_ci| LOG_FATAL | FATAL level to be used by **OH_LOG_FATAL**.| 288e41f4b71Sopenharmony_ci 289e41f4b71Sopenharmony_ci 290e41f4b71Sopenharmony_ci### LogType 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ci``` 293e41f4b71Sopenharmony_cienum LogType 294e41f4b71Sopenharmony_ci``` 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci**Description** 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ci**Log Type** 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ciYou can use this function to specify the type of output logs. Currently, only **LOG_APP** is available. 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ci**Since**: 8 303e41f4b71Sopenharmony_ci 304e41f4b71Sopenharmony_ci| Value| Description| 305e41f4b71Sopenharmony_ci| -------- | -------- | 306e41f4b71Sopenharmony_ci| LOG_APP | Application log.| 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_ci## Function Description 310e41f4b71Sopenharmony_ci 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ci### OH_LOG_IsLoggable() 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci``` 315e41f4b71Sopenharmony_ciint bool OH_LOG_IsLoggable (unsigned int domain, const char * tag, LogLevel level ) 316e41f4b71Sopenharmony_ci``` 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci**Description** 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ciChecks whether logs of the specified service domain, tag, and level can be printed. 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_ci**Since**: 8 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci**Parameters** 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ci| Name| Description| 327e41f4b71Sopenharmony_ci| -------- | -------- | 328e41f4b71Sopenharmony_ci| domain | Service domain.| 329e41f4b71Sopenharmony_ci| tag | Log tag.| 330e41f4b71Sopenharmony_ci| level | Log level.| 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci**Returns** 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci**true** if the specified logs can be output; **false** otherwise. 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_ci 337e41f4b71Sopenharmony_ci### OH_LOG_Print() 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ci``` 340e41f4b71Sopenharmony_ciint OH_LOG_Print (LogType type, LogLevel level, unsigned int domain, const char * tag, const char * fmt, ... ) 341e41f4b71Sopenharmony_ci``` 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_ci**Description** 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ciOutputs logs. 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ciYou can use this function to output logs based on the specified log type, log level, service domain, log tag, and variable parameters determined by the format specifier and privacy identifier in the printf format. 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci**Since**: 8 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ci**Parameters** 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci| Name| Description| 354e41f4b71Sopenharmony_ci| -------- | -------- | 355e41f4b71Sopenharmony_ci| type | Log type. The type for third-party applications is defined by **LOG_APP**.| 356e41f4b71Sopenharmony_ci| level | Log level. The value can be **LOG_DEBUG**, **LOG_INFO**, **LOG_WARN**, **LOG_ERROR**, and **LOG_FATAL**.| 357e41f4b71Sopenharmony_ci| domain | Service domain. Its value is a hexadecimal integer ranging from 0x0 to 0xFFFF.| 358e41f4b71Sopenharmony_ci| tag | Log tag, which is a string used to identify the class, file, or service.| 359e41f4b71Sopenharmony_ci| fmt | Format string, which is an enhancement of a printf format string and supports the privacy identifier. Specifically, **{public}** or **{private}** is added between the % character and the format specifier in each parameter.| 360e41f4b71Sopenharmony_ci| ... | Parameter list corresponding to the parameter type in the format string. The number and type of parameters must be mapped onto the identifier in the format string.| 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ci**Returns** 363e41f4b71Sopenharmony_ci 364e41f4b71Sopenharmony_ci**0** or a larger value if the operation is successful; a value smaller than **0** otherwise. 365e41f4b71Sopenharmony_ci 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ci### OH_LOG_SetCallback() 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci``` 370e41f4b71Sopenharmony_civoid OH_LOG_SetCallback (LogCallback callback) 371e41f4b71Sopenharmony_ci``` 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci**Description** 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_ciRegisters a callback function. 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ciAfter this function is called, the customized callback can take over all logs of the current process. Note that whether this API is called or not, it does not change the default log processing of the current process. 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci**Since**: 11 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ci**Parameters** 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_ci| Name| Description| 384e41f4b71Sopenharmony_ci| -------- | -------- | 385e41f4b71Sopenharmony_ci| callback | Custom callback function. If processing of logs is not needed, a null pointer can be transferred.| 386