harmony 鸿蒙log.h
log.h
Overview
Defines the logging functions of the HiLog module.
Before 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.
Log domain: service domain of logs. You can define the value as required. Its value is a hexadecimal integer ranging from 0x0 to 0xFFFF. If the value exceeds the range, logs cannot be printed.
Log tag: a string used to identify the class, file, or service behavior.
Log level: DEBUG, INFO, WARN, ERROR, or FATAL.
Parameter format: printf format string, which starts with a % character, including a parameter type identifier and a variable parameter.
Privacy identifier: {public} or {private} added between the % character and the parameter type identifier in each parameter. If no privacy identifier is added, the parameter is considered to be private.
Example
Define the service domain and tag:
#define LOG_DOMAIN 0x0201
#define LOG_TAG "MY_TAG"
Print the log:
HILOG_WARN(LOG_APP, "Failed to visit %{private}s, reason:%{public}d.", url, errno);
Output:
05-06 15:01:06.870 1051 1051 W 0201/MY_TAG: Failed to visit <private>, reason:503.
File to include:
System capability: SystemCapability.HiviewDFX.HiLog
Since: 8
Related module: HiLog
Summary
Macros
Name | Description |
---|---|
LOG_DOMAIN 0 | Indicates the service domain for a log file. |
LOG_TAG NULL | Indicates the string constant used to identify the class, file, or service. A tag can contain a maximum of 31 bytes. If a tag exceeds this limit, it will be truncated. Chinese characters are not recommended because garbled characters or alignment problems may occur. |
OH_LOG_DEBUG(type, …) ((void) OH_LOG_Print((type), LOG_DEBUG, LOG_DOMAIN, LOG_TAG, VA_ARGS)) | Indicates DEBUG logs. This is a function-like macro. Before using this macro, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file. |
OH_LOG_INFO(type, …) ((void) OH_LOG_Print((type), LOG_INFO, LOG_DOMAIN, LOG_TAG, VA_ARGS)) | Indicates INFO logs. This is a function-like macro. Before using this macro, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file. |
OH_LOG_WARN(type, …) ((void) OH_LOG_Print((type), LOG_WARN, LOG_DOMAIN, LOG_TAG, VA_ARGS)) | Indicates WARN logs. This is a function-like macro. Before using this macro, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file. |
OH_LOG_ERROR(type, …) ((void) OH_LOG_Print((type), LOG_ERROR, LOG_DOMAIN, LOG_TAG, VA_ARGS)) | Indicates ERROR logs. This is a function-like macro. Before using this macro, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file. |
OH_LOG_FATAL(type, …) ((void) OH_LOG_Print((type), LOG_FATAL, LOG_DOMAIN, LOG_TAG, VA_ARGS)) | Indicates FATAL logs. This is a function-like macro. Before using this macro, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file. |
Types
Name | Description |
---|---|
typedef void(* LogCallback) (const LogType type, const LogLevel level, const unsigned int domain, const char *tag, const char *msg) | Defines a function for customizing the processing of logs in the callback. |
Enums
Name | Description |
---|---|
LogType { LOG_APP = 0 } | Enumerates the log types. |
LogLevel { LOG_DEBUG = 3, LOG_INFO = 4, LOG_WARN = 5, LOG_ERROR = 6, LOG_FATAL = 7 } |
Enumerates the log levels. |
Functions
Name | Description |
---|---|
int OH_LOG_Print (LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt,…) attribute((format(os_log | Outputs logs of the specified type, level, domain, tag, and variables determined by the format specifier and privacy identifier in the printf format. |
int int OH_LOG_PrintMsg (LogType type, LogLevel level, unsigned int domain, const char *tag, const char *message) | Outputs constant log strings of the specified type, level, domain, and tag. |
int OH_LOG_PrintMsgByLen (LogType type, LogLevel level, unsigned int domain, const char *tag, size_t tagLen, const char *message, size_t messageLen) | Outputs constant log strings of the specified domain, tag, and level. The tag and string length must be specified. Unlike OH_LOG_PrintMsg, this API allows strings without terminators. |
int OH_LOG_VPrint (LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt, va_list ap) attribute((format(os_log | Outputs logs of specified type, level, domain, tag, and variables determined by the format specifier and privacy identifier in the printf format. The variables are of the va_list type. |
int bool OH_LOG_IsLoggable (unsigned int domain, const char *tag, LogLevel level) | Checks whether logs of the specified service domain, tag, and level can be printed. |
void OH_LOG_SetCallback (LogCallback callback) | Registers a callback function. |
void OH_LOG_SetMinLogLevel (LogLevel level) | Sets the minimum log level. When a process prints logs, both the minimum log level and global log level are verified. Therefore, the minimum log level cannot be lower than the global log level. The default global log level is Info. |
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Performance Analysis Kit
harmony 鸿蒙Performance Analysis Kit
harmony 鸿蒙HiAppEvent_AppEventGroup
harmony 鸿蒙HiAppEvent_AppEventInfo
harmony 鸿蒙HiCollie_DetectionParam
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦