Log guide

Updated at:

This topic describes the log system for the C Link SDK.

Overview

The C Link SDK log system is customizable for different development stages. You can modify the aiot_state_api.h file to:

  • Set the log level.

  • Customize log outputs.

  • Disable logs at compile-time.

Set the log level

Log level definitions:

typedef enum {
 LOG_LEVEL_NONE = 0, /* No logs are output */
 LOG_LEVEL_ERROR,
 LOG_LEVEL_INFO,
 LOG_LEVEL_DEBUG,
} log_level_t;

The default log output level is LOG_LEVEL_DEBUG. To change the log level, use the following interface:

/**
 * @brief Sets the log output level for the SDK.
 *
 * @param level The log level.
 *
 * @return int32_t Reserved.
 */
int32_t aiot_state_set_log_level(log_level_t level);

Customize log outputs

By default, the SDK uses printf for log output. You can use the following interfaces to customize the log output method.

/**
 * @brief Prototype of the log output callback function for the SDK.
 */
typedef int32_t (* aiot_state_logcb_t)(int32_t code, char *message);/**
 * @brief Sets the callback function used for SDK log output.
 *
 * @param handler The log callback function.
 *
 * @return int32_t Reserved.
 */
int32_t aiot_state_set_logcb(aiot_state_logcb_t handler);

Disable logs at compile-time

To disable all log outputs, comment out the following line of code. This action prevents the log code from being compiled into the library.

#define LOG_ENABLE