text: /*
   * Tencent is pleased to support the open source community by making IoT Hub available.
   * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
  
   * Licensed under the MIT License (the "License"); you may not use this file except in
   * compliance with the License. You may obtain a copy of the License at
   * http://opensource.org/licenses/MIT
  
   * Unless required by applicable law or agreed to in writing, software distributed under the License is
   * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
   * either express or implied. See the License for the specific language governing permissions and
   * limitations under the License.
   *
   */
  
  #ifndef QCLOUD_IOT_EXPORT_LOG_H_
  #define QCLOUD_IOT_EXPORT_LOG_H_
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  #include <stdio.h>
  #include <stdlib.h>
  #include <stdbool.h>
  #include <stdarg.h>
  
  /**
   * 日志输出等级
   */
  typedef enum {
      DEBUG,
      INFO,
      WARN,
      MQTT_ERROR
  } LOG_LEVEL;
  
  /**
   * 全局日志级别输出标志, 只输出小于或等于该等级的日志信息
   */
  extern LOG_LEVEL g_log_level;
  
  typedef bool (*LogMessageHandler)(const char* message);
  
  /**
   * @brief
   *
   * @param
   */
  void IOT_Log_Set_Level(LOG_LEVEL level);
  
  /**
   * @brief 获取当前日志等级
   *
   * @return
   */
  LOG_LEVEL IOT_Log_Get_Level();
  
  /**
   * @brief 设置日志回调函数，用户接管日志内容用于输出到文件等操作
   *
   * @param handler 回调函数指针
   *
   */
  void IOT_Log_Set_MessageHandler(LogMessageHandler handler);
  
  /**
   * @brief 日志打印函数，默认打印到标准输出，当用户设置日志打印handler时，回调handler
   *
   * @param file 源文件名
   * @param func 函数名
   * @param line 行号
   * @param level 日志等级
   */
  void Log_writter(const char *file, const char *func, const int line, const int level, const char *fmt, ...);
  
  #ifndef RELEASE_VERSION
  #define Log_d(args...) Log_writter(__FILE__, __FUNCTION__, __LINE__, DEBUG, args)
  #define Log_i(args...) Log_writter(__FILE__, __FUNCTION__, __LINE__, INFO, args)
  #define Log_w(args...) Log_writter(__FILE__, __FUNCTION__, __LINE__, WARN, args)
  #define Log_e(args...) Log_writter(__FILE__, __FUNCTION__, __LINE__, MQTT_ERROR, args)
  #else
  #define Log_d(args...) printk("")
  #define Log_i(args...) printk("")
  #define Log_w(args...) printk("")
  #define Log_e(args...) printk("")
  #endif
  
  #ifdef IOT_DEBUG
  	#define IOT_FUNC_ENTRY    \
  		{\
  		printf("FUNC_ENTRY:   %s L#%d \n", __FUNCTION__, __LINE__);  \
  		}
  	#define IOT_FUNC_EXIT    \
  		{\
  		printf("FUNC_EXIT:   %s L#%d \n", __FUNCTION__, __LINE__);  \
  		return;\
  		}
  	#define IOT_FUNC_EXIT_RC(x)    \
  		{\
  		printf("FUNC_EXIT:   %s L#%d Return Code : %ld \n", __FUNCTION__, __LINE__, (long)(x));  \
  		return x; \
  		}
  #else
  	#define IOT_FUNC_ENTRY
  	#define IOT_FUNC_EXIT 			\
  		{\
  			return;\
  		}
  	#define IOT_FUNC_EXIT_RC(x)     \
  		{\
  			return x; \
  		}
  #endif
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* QCLOUD_IOT_EXPORT_LOG_H_ */
  