Local Log

Last Updated on : 2022-11-24 09:20:20download

When you debug your application code, logs can help you determine the severity of a problem, identify contributing factors, and quickly resolve them. This topic describes how to configure the logger to suit your requirements.

Logging configuration

Logging APIs

This section describes the APIs used to configure the logger.

Turn on/off logging

Function prototype void tuya_user_elog_switch (IN bool on)
Parameter
  • true: Turn on logging.
  • false: Turn off logging.
Feature Turn on or off logging. The change takes effect after the system restart. Turning on logging will increase power consumption.
Header file #include <tuya_user_api.h>
Return value None

Log output format

Function prototype char *tuya_user_api_enum2str (ENUM_STR_T *a, int v)
Parameter
  • a: The defined enumeration. For more information, see the struct ENUM_STR_T.
  • v: The specified enum value. For more information, see COMMON_CMD_E.
Feature Specify the string that corresponds to a defined enum value as the log output.
Header file #include <tuya_user_api.h>
Return value The string that corresponds to the specified enum value.
typedef struct {
  int  enum_val;  // The enum value.
  char* string;   // The string that corresponds to a specific enum value.
} ENUM_STR_T;

Logging level

Function prototype void tuya_user_api_set_sdk_dbg_filter_level (unsigned char filter_level)
Parameter filter_level: The specified logging level for the SDK. For more information, see filter_level.
Feature Set the logging level to classify the entries in the SDK log file in terms of severity.
Header file #include <tuya_user_api.h>
Return value None

The macro definition for filter_level.

The following logging levels are available, from the lowest to the highest. The higher levels always include the messages from the lower levels. For example, if you select ELOG_LVL_INFO, info, warn, error, and assert messages are included.

  • ELOG_LVL_ASSERT: the value of 0. Log events at the assert level.
  • ELOG_LVL_ERROR: the value of 1. Call USER_API_LOGE to log events at the error or lower levels.
  • ELOG_LVL_WARN: the value of 2. Call USER_API_LOGW to log events at the warn or lower levels.
  • ELOG_LVL_INFO: the value of 3. Call USER_API_LOGI to log events at the info or lower levels.
  • ELOG_LVL_DEBUG: the value of 4. Call USER_API_LOGD to log events at the debug or lower levels.
  • ELOG_LVL_VERBOSE: the value of 5. Call USER_API_LOGV to log events at the verbose or lower levels.

Output logs in hex format

Function prototype #define USER_API_HEX_DUMP(name, width, buf, size) elog_hexdump(name, width, buf, size)
Parameter
  • name: The object identifier of the data to be printed, displayed on the header.
  • width: The number of hex characters in a line. For example, 16 or 32.
  • buf: The pointer to the buffer where data to be printed is stored.
  • size: The size of the data to be printed.
Feature Output logs in hex format
Header file #include <tuya_user_api.h>
Return value None