linux-debug-with log file
来源:互联网 发布:soc管理平台 知乎 编辑:程序博客网 时间:2024/06/07 00:12
/***********************************************************************************************************/
/* Description:This file used to print special text with linux OS. */
/* Author:DingChongChong */
/* Time:20160315 */
/* Release:1.2 */
/***********************************************************************************************************/
#ifndef _DEBUG_H
#define _DEBUG_H
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include <sys/time.h>
#include <unistd.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>
static char * pEnv;
struct timeval tv;
static int fd;
static char logBuff[100];
#define FUNC_ENTRY "\033[1;32m[%ld:%ld][%s %d][FuncEntry]:"
#define FUNC_ENTRY_TAIL "\033[m"
#define MENU_ECHO "\033[1;35m<----------------"
#define MENU_ECHO_TAIL "---------------->\033[m\n"
#define PROMPT_ECHO "\033[1;36m[%ld:%ld][%s %d][PromptEcho]:"
#define PROMPT_ECHO_TAIL "\033[m"
#define DATA_ECHO "\033[1;34m[%ld:%ld][%s %d][DataEcho]:"
#define DATA_ECHO_TAIL "\033[m"
#define WARN_ECHO "\033[1;33m[%ld:%ld][%s %d][WarnEcho]:"
#define WARN_ECHO_TAIL "\033[m"
#define ERROR_OCCUR "\033[1;31m[%ld:%ld][%s %d][ErrorOccur]:"
#define ERROR_OCCUR_TAIL "\033[m"
#define debugInit() do{ pEnv=getenv("DEBUG"); \
remove("debug.log");\
fd=open("debug.log",O_WRONLY|O_CREAT|O_EXCL|O_TRUNC,S_IRUSR); }while(0)
#define debugUninit() do{ close(fd);}while(0)
#define debugFuncEcho(fmt, args...) do {gettimeofday(&tv,NULL); \
if((pEnv!=NULL)&&(0==strcmp(pEnv,"ON"))) {\
printf(FUNC_ENTRY fmt FUNC_ENTRY_TAIL,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout);\
sprintf(logBuff,"[%ld:%ld][%s %d][FuncEntry]:" fmt,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout);\
write(fd,logBuff,strlen(logBuff));}}while(0)
#define debugMenuEcho(fmt, args...) do {gettimeofday(&tv,NULL); \
if((pEnv!=NULL)&&(0==strcmp(pEnv,"ON"))) {\
printf(MENU_ECHO fmt MENU_ECHO_TAIL,##args);fflush(stdout); }}while(0)
#define debugPromptEcho(fmt, args...) do { gettimeofday(&tv,NULL); \
if((pEnv!=NULL)&&(0==strcmp(pEnv,"ON"))) {\
printf(PROMPT_ECHO fmt PROMPT_ECHO_TAIL,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout); \
sprintf(logBuff,"[%s %d][PromptEcho]:" fmt,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout); \
write(fd,logBuff,strlen(logBuff));}}while(0)
#define debugDataEcho(fmt, args...) do {gettimeofday(&tv,NULL); \
if((pEnv!=NULL)&&(0==strcmp(pEnv,"ON"))) {\
printf(DATA_ECHO fmt DATA_ECHO_TAIL,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout);\
sprintf(logBuff,"[%ld:%ld][%ld:%ld][ %s %d][DataEcho]:" fmt,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout);\
write(fd,logBuff,strlen(logBuff));}}while(0)
#define debugWarnEcho(fmt, args...) do {gettimeofday(&tv,NULL); \
if((pEnv!=NULL)&&(0==strcmp(pEnv,"ON"))){ \
printf(WARN_ECHO fmt WARN_ECHO_TAIL,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout);\
sprintf(logBuff,"[%ld:%ld][ %s %d][WarnEcho]:" fmt,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout);\
write(fd,logBuff,strlen(logBuff));}}while(0)
#define debugErrorEcho(fmt, args...) do {gettimeofday(&tv,NULL); \
if((pEnv!=NULL)&&(0==strcmp(pEnv,"ON"))){ \
printf(ERROR_OCCUR fmt ERROR_OCCUR_TAIL,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout); \
sprintf(logBuff,"[%ld:%ld][ %s %d][ErrorOccur]:" fmt,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout); \
write(fd,logBuff,strlen(logBuff));}}while(0)
#endif
/* Begin:"\033[Bright;BackColor;FontColor m"
* Bright: 0-no,1-yes
* BackColor: 40:black - 41:red - 42:green - 43:yellow - 44:cyan - 45:blue - 47:white
* FontColor: 30:black - 31:red - 32:green - 33:yellow - 34:blue - 35:purple - 36:cyan - 37:white
* End:"\033[m"
*/
/* Description:This file used to print special text with linux OS. */
/* Author:DingChongChong */
/* Time:20160315 */
/* Release:1.2 */
/***********************************************************************************************************/
#ifndef _DEBUG_H
#define _DEBUG_H
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include <sys/time.h>
#include <unistd.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>
static char * pEnv;
struct timeval tv;
static int fd;
static char logBuff[100];
#define FUNC_ENTRY "\033[1;32m[%ld:%ld][%s %d][FuncEntry]:"
#define FUNC_ENTRY_TAIL "\033[m"
#define MENU_ECHO "\033[1;35m<----------------"
#define MENU_ECHO_TAIL "---------------->\033[m\n"
#define PROMPT_ECHO "\033[1;36m[%ld:%ld][%s %d][PromptEcho]:"
#define PROMPT_ECHO_TAIL "\033[m"
#define DATA_ECHO "\033[1;34m[%ld:%ld][%s %d][DataEcho]:"
#define DATA_ECHO_TAIL "\033[m"
#define WARN_ECHO "\033[1;33m[%ld:%ld][%s %d][WarnEcho]:"
#define WARN_ECHO_TAIL "\033[m"
#define ERROR_OCCUR "\033[1;31m[%ld:%ld][%s %d][ErrorOccur]:"
#define ERROR_OCCUR_TAIL "\033[m"
#define debugInit() do{ pEnv=getenv("DEBUG"); \
remove("debug.log");\
fd=open("debug.log",O_WRONLY|O_CREAT|O_EXCL|O_TRUNC,S_IRUSR); }while(0)
#define debugUninit() do{ close(fd);}while(0)
#define debugFuncEcho(fmt, args...) do {gettimeofday(&tv,NULL); \
if((pEnv!=NULL)&&(0==strcmp(pEnv,"ON"))) {\
printf(FUNC_ENTRY fmt FUNC_ENTRY_TAIL,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout);\
sprintf(logBuff,"[%ld:%ld][%s %d][FuncEntry]:" fmt,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout);\
write(fd,logBuff,strlen(logBuff));}}while(0)
#define debugMenuEcho(fmt, args...) do {gettimeofday(&tv,NULL); \
if((pEnv!=NULL)&&(0==strcmp(pEnv,"ON"))) {\
printf(MENU_ECHO fmt MENU_ECHO_TAIL,##args);fflush(stdout); }}while(0)
#define debugPromptEcho(fmt, args...) do { gettimeofday(&tv,NULL); \
if((pEnv!=NULL)&&(0==strcmp(pEnv,"ON"))) {\
printf(PROMPT_ECHO fmt PROMPT_ECHO_TAIL,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout); \
sprintf(logBuff,"[%s %d][PromptEcho]:" fmt,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout); \
write(fd,logBuff,strlen(logBuff));}}while(0)
#define debugDataEcho(fmt, args...) do {gettimeofday(&tv,NULL); \
if((pEnv!=NULL)&&(0==strcmp(pEnv,"ON"))) {\
printf(DATA_ECHO fmt DATA_ECHO_TAIL,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout);\
sprintf(logBuff,"[%ld:%ld][%ld:%ld][ %s %d][DataEcho]:" fmt,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout);\
write(fd,logBuff,strlen(logBuff));}}while(0)
#define debugWarnEcho(fmt, args...) do {gettimeofday(&tv,NULL); \
if((pEnv!=NULL)&&(0==strcmp(pEnv,"ON"))){ \
printf(WARN_ECHO fmt WARN_ECHO_TAIL,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout);\
sprintf(logBuff,"[%ld:%ld][ %s %d][WarnEcho]:" fmt,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout);\
write(fd,logBuff,strlen(logBuff));}}while(0)
#define debugErrorEcho(fmt, args...) do {gettimeofday(&tv,NULL); \
if((pEnv!=NULL)&&(0==strcmp(pEnv,"ON"))){ \
printf(ERROR_OCCUR fmt ERROR_OCCUR_TAIL,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout); \
sprintf(logBuff,"[%ld:%ld][ %s %d][ErrorOccur]:" fmt,tv.tv_sec,tv.tv_usec,__FILE__,__LINE__,##args);fflush(stdout); \
write(fd,logBuff,strlen(logBuff));}}while(0)
#endif
/* Begin:"\033[Bright;BackColor;FontColor m"
* Bright: 0-no,1-yes
* BackColor: 40:black - 41:red - 42:green - 43:yellow - 44:cyan - 45:blue - 47:white
* FontColor: 30:black - 31:red - 32:green - 33:yellow - 34:blue - 35:purple - 36:cyan - 37:white
* End:"\033[m"
*/
0 0
- linux-debug-with log file
- npm ERR!Please include the following file with any support request...../npm-debug.log
- Write log file with .net
- Skills for generating debug log file
- Debug Linux Kernel with Qemu
- Debug a built binary file with VS and *.pdb file
- php ajax debug method -- make log in a text file
- How to generate an AR debug log file
- How to generate an AP debug log file
- How to generate an GL debug log file
- How to generate an GL debug log file .
- How to generate an AP debug log file
- linux gpio debug log(AM335X)
- debug log
- debug log
- Linux - C++ - Print log to file
- log file
- dup() ---- Linux function dup() to save debug log.
- pandas 常用函数
- 6.icon font技术应用
- python gevent
- quick 3.3 按钮多次点击出现问题的解决
- zabbix3.0安装
- linux-debug-with log file
- Rust的数据类型和功能函数的返回值
- deepin下bochs的配置
- VS,C#--拼图小游戏
- C语言中的goto
- 当View为GONE状态时获取View的宽高
- 学习知识总结
- 类方法和实例方法的区别
- GLSL学习笔记---之内建变量2