harmony 鸿蒙log.h

  • 2023-06-24
  • 浏览 (632)

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.

Service domain: service domain of logs. You can define the value as required. Its value is a hexadecimal integer ranging from 0x0 to 0xFFFF.

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.

Sample code:

Defining the service domain and log tag:

#define LOG_DOMAIN 0x0201

#define LOG_TAG “MY_TAG”

Outputting logs:

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.

Since: 8

Related Modules:

HiLog

Summary

Macros

Name Description
LOG_DOMAIN 0 Defines the service domain for a log file.
LOG_TAG NULL Defines a string constant used to identify the class, file, or service.
OH_LOG_DEBUG(type, …) ((void)OH_LOG_Print((type), LOG_DEBUG, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) Outputs DEBUG logs. This is a function-like macro.
OH_LOG_INFO(type, …) ((void)OH_LOG_Print((type), LOG_INFO, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) Outputs INFO logs. This is a function-like macro.
OH_LOG_WARN(type, …) ((void)OH_LOG_Print((type), LOG_WARN, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) Outputs WARN logs. This is a function-like macro.
OH_LOG_ERROR(type, …) ((void)OH_LOG_Print((type), LOG_ERROR, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) Outputs ERROR logs. This is a function-like macro.
OH_LOG_FATAL(type, …) ((void)HiLogPrint((type), LOG_FATAL, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) Outputs FATAL logs. This is a function-like macro.

Enums

Name Description
LogType { LOG_APP = 0 } Enumerates log types.
LogLevel {
LOG_DEBUG = 3, LOG_INFO = 4, LOG_WARN = 5, LOG_ERROR = 6,
LOG_FATAL = 7
}
Enumerates log levels.

Functions

Name Description
OH_LOG_Print (LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt,…) __attribute((__format(os_log, 5, 6))) Outputs logs.
OH_LOG_IsLoggable (unsigned int domain, const char *tag, LogLevel level) Checks whether logs of the specified service domain, log tag, and log level can be output.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Native APIs

harmony 鸿蒙AVCapability

harmony 鸿蒙AVDemuxer

harmony 鸿蒙AVMuxer

harmony 鸿蒙AVScreenCapture

harmony 鸿蒙AVSource

harmony 鸿蒙AudioDecoder

harmony 鸿蒙AudioEncoder

harmony 鸿蒙CodecBase

harmony 鸿蒙Core

0  赞