#ifndef TOOLS_PDEBUG_H_
#define TOOLS_PDEBUG_H_

#include <stdio.h>
#include <string.h>
#include "uart_dev.h"
// #include "pdebug.h"

/* Comment out this define to include debug messages */
// #define NDEBUG

#define log_info_enable     1
#define log_warn_enable     1
#define log_error_enable    1

/* Comment out this define to include log messages */
// #define NLOG

#ifdef NDEBUG
#define debug(M, ...)   do {}while(0)
#else
#define debug(M, ...)   debug_printf("%s:%d: " M "\r\n", __FILE__, __LINE__, ##__VA_ARGS__)
#endif

#ifdef NLOG
#define log_err(M, ...)     do {}while(0)
#define log_warn(M, ...)    do {}while(0)
#define log_info(M, ...)    do {}while(0)
#else
#define log_info(M, ...)    {if(log_info_enable){char *p = strrchr(__FILE__, '\\'); debug_printf("[INFO] [%s:%d] " M "\r\n", p+1, __LINE__, ##__VA_ARGS__);}}
#define log_warn(M, ...)    {if(log_warn_enable){char *p = strrchr(__FILE__, '\\'); debug_printf("[WARN] [%s:%d] " M "\r\n", p+1, __LINE__, ##__VA_ARGS__);}}
#define log_error(M, ...)   {if(log_error_enable){char *p = strrchr(__FILE__, '\\'); debug_printf("[ERROR] [%s:%d] " M "\r\n", p+1, __LINE__,##__VA_ARGS__);}}
#endif

#endif