首页 > 代码库 > print to console or file
print to console or file
/*----------------------------------------------------------------------*/
/* Debug for embeded board, 2008-2-26, Rain. */
/*----------------------------------------------------------------------*/
#define PRINT_DEBUG 1
#define UNDERLINE "\033[4m"
#define BLACK "\033[30m"
#define RED "\033[31m"
#define GREEN "\033[32m"
#define YELLOW "\033[33m"
#define BLUE "\033[34m"
#define PURPLE "\033[35m"
#define DARKGREEN "\033[36m"
#define WHITE "\033[37m"
#define BG_BLACK "\033[40m"
#define BG_RED "\033[41m"
#define BG_GREEN "\033[42m"
#define BG_YELLOW "\033[43m"
#define BG_BLUE "\033[44m"
#define BG_PURPLE "\033[45m"
#define BG_DARKGREEN "\033[46m"
#define BG_WHITE "\033[47m"
#define CLOSE "\033[0m"
#define cprintf(fmt, args...) do \
{ \
FILE *fp1 = fopen("/dev/tty", "a"); \
FILE *fp2 = fopen("/tmp/dbg.txt", "a"); \
int flag = 0; \
if (fp1 && (flag == 0 || flag == 2)) { \
fprintf(fp1, fmt, ## args); \
fclose(fp1); \
} \
if (fp2 && (flag == 1 || flag == 2)) { \
fprintf(fp2, fmt, ## args); \
fclose(fp2); \
} \
} while (0)
#ifdef PRINT_DEBUG
#define dbg(fmt, args...) \
cprintf("==> CGI_DEBUG %s | %s %d | " fmt CLOSE, __FILE__, __FUNCTION__, __LINE__, ##args)
#else
#define dbg(fmt, args...)
#endif
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* Debug for SSH terminal, 2008-2-26, Rain. */
/*----------------------------------------------------------------------*/
#define PRINT_DEBUG 1
#define UNDERLINE "\033[4m"
#define BLACK "\033[30m"
#define RED "\033[31m"
#define GREEN "\033[32m"
#define YELLOW "\033[33m"
#define BLUE "\033[34m"
#define PURPLE "\033[35m"
#define DARKGREEN "\033[36m"
#define WHITE "\033[37m"
#define BG_BLACK "\033[40m"
#define BG_RED "\033[41m"
#define BG_GREEN "\033[42m"
#define BG_YELLOW "\033[43m"
#define BG_BLUE "\033[44m"
#define BG_PURPLE "\033[45m"
#define BG_DARKGREEN "\033[46m"
#define BG_WHITE "\033[47m"
#define CLOSE "\033[0m"
#define cprintf(fmt, args...) do \
{ \
char *dev = getenv("SSH_TTY"); \
FILE *fp1 = fopen(dev, "a"); \
FILE *fp2 = fopen("/tmp/dbg.txt", "a"); \
int flag = 0; \
if (fp1 && (flag == 0 || flag == 2)) { \
fprintf(fp1, fmt, ## args); \
fclose(fp1); \
} \
if (fp2 && (flag == 1 || flag == 2)) { \
fprintf(fp2, fmt, ## args); \
fclose(fp2); \
} \
} while (0)
#ifdef PRINT_DEBUG
#define dbg(fmt, args...) \
cprintf("==> CGI_DEBUG %s | %s %d | " fmt CLOSE, __FILE__, __FUNCTION__, __LINE__, ##args)
#else
#define dbg(fmt, args...)
#endif
/*----------------------------------------------------------------------*/
/* Debug for embeded board, 2008-2-26, Rain. */
/*----------------------------------------------------------------------*/
#define PRINT_DEBUG 1
#define UNDERLINE "\033[4m"
#define BLACK "\033[30m"
#define RED "\033[31m"
#define GREEN "\033[32m"
#define YELLOW "\033[33m"
#define BLUE "\033[34m"
#define PURPLE "\033[35m"
#define DARKGREEN "\033[36m"
#define WHITE "\033[37m"
#define BG_BLACK "\033[40m"
#define BG_RED "\033[41m"
#define BG_GREEN "\033[42m"
#define BG_YELLOW "\033[43m"
#define BG_BLUE "\033[44m"
#define BG_PURPLE "\033[45m"
#define BG_DARKGREEN "\033[46m"
#define BG_WHITE "\033[47m"
#define CLOSE "\033[0m"
#define cprintf(fmt, args...) do \
{ \
FILE *fp1 = fopen("/dev/tty", "a"); \
FILE *fp2 = fopen("/tmp/dbg.txt", "a"); \
int flag = 0; \
if (fp1 && (flag == 0 || flag == 2)) { \
fprintf(fp1, fmt, ## args); \
fclose(fp1); \
} \
if (fp2 && (flag == 1 || flag == 2)) { \
fprintf(fp2, fmt, ## args); \
fclose(fp2); \
} \
} while (0)
#ifdef PRINT_DEBUG
#define dbg(fmt, args...) \
cprintf("==> CGI_DEBUG %s | %s %d | " fmt CLOSE, __FILE__, __FUNCTION__, __LINE__, ##args)
#else
#define dbg(fmt, args...)
#endif
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* Debug for SSH terminal, 2008-2-26, Rain. */
/*----------------------------------------------------------------------*/
#define PRINT_DEBUG 1
#define UNDERLINE "\033[4m"
#define BLACK "\033[30m"
#define RED "\033[31m"
#define GREEN "\033[32m"
#define YELLOW "\033[33m"
#define BLUE "\033[34m"
#define PURPLE "\033[35m"
#define DARKGREEN "\033[36m"
#define WHITE "\033[37m"
#define BG_BLACK "\033[40m"
#define BG_RED "\033[41m"
#define BG_GREEN "\033[42m"
#define BG_YELLOW "\033[43m"
#define BG_BLUE "\033[44m"
#define BG_PURPLE "\033[45m"
#define BG_DARKGREEN "\033[46m"
#define BG_WHITE "\033[47m"
#define CLOSE "\033[0m"
#define cprintf(fmt, args...) do \
{ \
char *dev = getenv("SSH_TTY"); \
FILE *fp1 = fopen(dev, "a"); \
FILE *fp2 = fopen("/tmp/dbg.txt", "a"); \
int flag = 0; \
if (fp1 && (flag == 0 || flag == 2)) { \
fprintf(fp1, fmt, ## args); \
fclose(fp1); \
} \
if (fp2 && (flag == 1 || flag == 2)) { \
fprintf(fp2, fmt, ## args); \
fclose(fp2); \
} \
} while (0)
#ifdef PRINT_DEBUG
#define dbg(fmt, args...) \
cprintf("==> CGI_DEBUG %s | %s %d | " fmt CLOSE, __FILE__, __FUNCTION__, __LINE__, ##args)
#else
#define dbg(fmt, args...)
#endif
/*----------------------------------------------------------------------*/
print to console or file
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。