HiLog

Overview

Provides logging functions.

For example, you can use these functions to output logs of the specified log type, service domain, log tag, and log level.

Since:

1.1

Version:

1.0

Summary

Macros

Macro Name and Value

Description

LOGDOMAIN   0

Defines the service domain for a log file.

LOGTAG   NULL

Defines a string constant used to identify the class, file, or service behavior.

HILOGDEBUG(type, …)   ((void)HiLogPrint(LOGCORE, LOGDEBUG, LOGDOMAIN, LOGTAG, VA_ARGS))

Outputs debug logs. This is a function-like macro.

HILOGINFO(type, …)   ((void)HiLogPrint(LOG_CORE, LOG_INFO, LOG_DOMAIN, LOG_TAG, __VA_ARGS))

Outputs informational logs. This is a function-like macro.

HILOG_WARN(type, …)   ((void)HiLogPrint(LOG_CORE, LOG_WARN, LOG_DOMAIN, LOG_TAG, __VA_ARGS))

Outputs warning logs. This is a function-like macro.

HILOG_ERROR(type, …)   ((void)HiLogPrint(LOG_CORE, LOG_ERROR, LOG_DOMAIN, LOG_TAG, __VA_ARGS))

Outputs error logs. This is a function-like macro.

HILOG_FATAL(type, …)   ((void)HiLogPrint(LOG_CORE, LOG_FATAL, LOG_DOMAIN, LOG_TAG, __VA_ARGS))

Outputs fatal logs. This is a function-like macro.

Enumerations

Enumeration Name

Description

HiLogModuleType {   HILOG_MODULE_HIVIEW = 0, HILOG_MODULE_SAMGR, HILOG_MODULE_ACE, HILOG_MODULE_APP,   HILOG_MODULE_MAX }

Enumerates logging module types.

LogType

Enumerates log types.

LogLevel {   LOG_DEBUG = 3, LOG_INFO = 4, LOG_WARN = 5, LOG_ERROR = 6,   LOG_FATAL = 7 }

Enumerates log levels.

Functions

Function Name

Description

HiLogPrint (LogType type, LogLevel level, unsigned int domain, const char tag, const char fmt,…) attribute((format(os_log

int 

Outputs logs.

Details

Macro Definition Documentation

HILOG_DEBUG

  1. #define HILOG_DEBUG( type, ... ) ((void)[HiLogPrint]($api-api-SmartVision-Devices-HiLog.md#ga4c59c13fccc59c5821b23865fbc6380f)(LOG_CORE, [LOG_DEBUG]($api-api-SmartVision-Devices-HiLog.md#ggaca1fd1d8935433e6ba2e3918214e07f9ab9f002c6ffbfd511da8090213227454e), [LOG_DOMAIN]($api-api-SmartVision-Devices-HiLog.md#ga95a1d08c807e0aada863b5298a61d08d), [LOG_TAG]($api-api-SmartVision-Devices-HiLog.md#ga7ce0df38eb467e59f209470c8f5ac4e6), __VA_ARGS__))

Description:

Outputs debug logs. This is a function-like macro.

Before calling this function, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file.

Parameters:

Name

Description

type Indicates the log type. The type for third-party applications is defined by LOG_APP.
fmt Indicates the 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.
Indicates a list of parameters. The number and type of parameters must map onto the format specifiers in the format string.

Returns:

Returns 0 or a larger value if the operation is successful; returns a value smaller than 0 otherwise.

See also:

HiLogPrint

HILOG_ERROR

  1. #define HILOG_ERROR( type, ... ) ((void)[HiLogPrint]($api-api-SmartVision-Devices-HiLog.md#ga4c59c13fccc59c5821b23865fbc6380f)(LOG_CORE, [LOG_ERROR]($api-api-SmartVision-Devices-HiLog.md#ggaca1fd1d8935433e6ba2e3918214e07f9a230506cce5c68c3bac5a821c42ed3473), [LOG_DOMAIN]($api-api-SmartVision-Devices-HiLog.md#ga95a1d08c807e0aada863b5298a61d08d), [LOG_TAG]($api-api-SmartVision-Devices-HiLog.md#ga7ce0df38eb467e59f209470c8f5ac4e6), __VA_ARGS__))

Description:

Outputs error logs. This is a function-like macro.

Before calling this function, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file.

Parameters:

Name

Description

type Indicates the log type. The type for third-party applications is defined by LOG_APP.
fmt Indicates the 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.
Indicates a list of parameters. The number and type of parameters must map onto the format specifiers in the format string.

Returns:

Returns 0 or a larger value if the operation is successful; returns a value smaller than 0 otherwise.

See also:

HiLogPrint

HILOG_FATAL

  1. #define HILOG_FATAL( type, ... ) ((void)[HiLogPrint]($api-api-SmartVision-Devices-HiLog.md#ga4c59c13fccc59c5821b23865fbc6380f)(LOG_CORE, [LOG_FATAL]($api-api-SmartVision-Devices-HiLog.md#ggaca1fd1d8935433e6ba2e3918214e07f9ac630750884d91cb9767ef2200bbb048b), [LOG_DOMAIN]($api-api-SmartVision-Devices-HiLog.md#ga95a1d08c807e0aada863b5298a61d08d), [LOG_TAG]($api-api-SmartVision-Devices-HiLog.md#ga7ce0df38eb467e59f209470c8f5ac4e6), __VA_ARGS__))

Description:

Outputs fatal logs. This is a function-like macro.

Before calling this function, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file.

Parameters:

Name

Description

type Indicates the log type. The type for third-party applications is defined by LOG_APP.
fmt Indicates the 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.
Indicates a list of parameters. The number and type of parameters must map onto the format specifiers in the format string.

Returns:

Returns 0 or a larger value if the operation is successful; returns a value smaller than 0 otherwise.

See also:

HiLogPrint

HILOG_INFO

  1. #define HILOG_INFO( type, ... ) ((void)[HiLogPrint]($api-api-SmartVision-Devices-HiLog.md#ga4c59c13fccc59c5821b23865fbc6380f)(LOG_CORE, [LOG_INFO]($api-api-SmartVision-Devices-HiLog.md#ggaca1fd1d8935433e6ba2e3918214e07f9a6e98ff471e3ce6c4ef2d75c37ee51837), [LOG_DOMAIN]($api-api-SmartVision-Devices-HiLog.md#ga95a1d08c807e0aada863b5298a61d08d), [LOG_TAG]($api-api-SmartVision-Devices-HiLog.md#ga7ce0df38eb467e59f209470c8f5ac4e6), __VA_ARGS__))

Description:

Outputs informational logs. This is a function-like macro.

Before calling this function, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file.

Parameters:

Name

Description

type Indicates the log type. The type for third-party applications is defined by LOG_APP.
fmt Indicates the 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.
Indicates a list of parameters. The number and type of parameters must map onto the format specifiers in the format string.

Returns:

Returns 0 or a larger value if the operation is successful; returns a value smaller than 0 otherwise.

See also:

HiLogPrint

HILOG_WARN

  1. #define HILOG_WARN( type, ... ) ((void)[HiLogPrint]($api-api-SmartVision-Devices-HiLog.md#ga4c59c13fccc59c5821b23865fbc6380f)(LOG_CORE, [LOG_WARN]($api-api-SmartVision-Devices-HiLog.md#ggaca1fd1d8935433e6ba2e3918214e07f9ac8041ffa22bc823d4726701cdb13fc13), [LOG_DOMAIN]($api-api-SmartVision-Devices-HiLog.md#ga95a1d08c807e0aada863b5298a61d08d), [LOG_TAG]($api-api-SmartVision-Devices-HiLog.md#ga7ce0df38eb467e59f209470c8f5ac4e6), __VA_ARGS__))

Description:

Outputs warning logs. This is a function-like macro.

Before calling this function, define the log service domain and log tag. Generally, you need to define them at the beginning of the source file.

Parameters:

Name

Description

type Indicates the log type. The type for third-party applications is defined by LOG_APP.
fmt Indicates the 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.
Indicates a list of parameters. The number and type of parameters must map onto the format specifiers in the format string.

Returns:

Returns 0 or a larger value if the operation is successful; returns a value smaller than 0 otherwise.

See also:

HiLogPrint

LOG_DOMAIN

  1. #define LOG_DOMAIN 0

Description:

Defines the service domain for a log file.

The service domain is used to identify the subsystem and module of a service. Its value is a hexadecimal integer ranging from 0x0 to 0xFFFFF. If the value is beyond the range, its significant bits are automatically truncated. The recommended format is 0xAAABB, where AAA indicates the subsystem and BB indicates the module.

LOG_TAG

  1. #define LOG_TAG [NULL]($api-api-SmartVision-Devices-UTILS.md#ga070d2ce7b6bb7e5c05602aa8c308d0c4)

Description:

Defines a string constant used to identify the class, file, or service behavior.

Enumeration Type Documentation

HiLogModuleType

  1. enum [HiLogModuleType]($api-api-SmartVision-Devices-HiLog.md#ga125ab0014dcc2b2152e0be2e39e31b9e)

Description:

Enumerates logging module types.

The module type must be globally unique. A maximum of 64 module types can be defined.

Enumerator

Description

HILOG_MODULE_HIVIEW 

DFX

HILOG_MODULE_SAMGR 

System Ability Manager

HILOG_MODULE_ACE 

Update

HILOG_MODULE_APP 

Third-party applications

HILOG_MODULE_MAX 

Maximum number of modules

LogLevel

  1. enum [LogLevel]($api-api-SmartVision-Devices-HiLog.md#gaca1fd1d8935433e6ba2e3918214e07f9)

Description:

Enumerates log levels.

You are advised to select log levels based on their respective usage scenarios:

Enumerator

Description

LOG_DEBUG 

Debug level to be used by HILOG_DEBUG

LOG_INFO 

Informational level to be used by HILOG_INFO

LOG_WARN 

Warning level to be used by HILOG_WARN

LOG_ERROR 

Error level to be used by HILOG_ERROR

LOG_FATAL 

Fatal level to be used by HILOG_FATAL

LogType

  1. enum [LogType]($api-api-SmartVision-Devices-HiLog.md#gaf67907baa897e9fb84df0cb89795b87c)

Description:

Enumerates log types.

Currently, LOG_APP is available.

Function Documentation

HiLogPrint()

  1. int HiLogPrint ([LogType]($api-api-SmartVision-Devices-HiLog.md#gaf67907baa897e9fb84df0cb89795b87c) type, [LogLevel]($api-api-SmartVision-Devices-HiLog.md#gaca1fd1d8935433e6ba2e3918214e07f9) level, unsigned int domain, const char * tag, const char * fmt, ... )

Description:

Outputs logs.

You 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.

Parameters:

Name

Description

type Indicates the log type. The type for third-party applications is defined by LOG_APP.
level Indicates the log level, which can be LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, and LOG_FATAL.
domain Indicates the service domain of logs. Its value is a hexadecimal integer ranging from 0x0 to 0xFFFFF. The recommended format is 0xAAABB, where AAA indicates the subsystem and BB indicates the module.
tag Indicates the log tag, which is a string used to identify the class, file, or service behavior.
fmt Indicates the 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.
Indicates a list of parameters. The number and type of parameters must map onto the format specifiers in the format string.

Returns:

Returns 0 or a larger value if the operation is successful; returns a value smaller than 0 otherwise.