当一个项目中需要输出内容或者打印日志时
一般不直接使用printf()
printf(“file:%s function:%s line:%d xxx”,FILE,func,LINE)
日志级别:
企业开发打印 一般都是按级别打印
TRACE DEBUG INFO WARRING ERROR FATAL
下面一般都在项目中显示你需要的输出,可以知道具体输出的是哪一行的内容,或者是你哪一行代码出错,查起来也方便。
#define LOG_FATAL(format,args…)
if(loglevel>0){
time_t t = time(NULL);
printf("[fatal] %s %s %s() %d : "format,ctime(&t),FILE,func,LINE,##args);}
#define LOG_ERROR(format,args…)
if(loglevel>1){
time_t t = time(NULL);
printf("[error] %s %s %s() %d : "format,ctime(&t),FILE,func,LINE,##args);}
#define LOG_INFO(format,args…)
if(loglevel>2) {
time_t t = time(NULL);
printf("[info] %s %s %s() %d : "format,ctime(&t),FILE,func,LINE,##args);}
写项目时用来输出,判错