将日志写到文件中去,在到文件中去看日志
例如:
int mig_log(fmt,va_alist)
char *fmt ;
va_dcl
{
va_list ap ;
FILE *fp ;
char log_file[81] ;
struct tm *p_tm ;
time_t clock ;
ap=(char *)&va_alist ;
time(&clock) ;
p_tm=localtime(&clock) ;
sprintf(log_file,"%s/mig_%4d%.2d%.2d.log",
getenv("HOME"),
p_tm->tm_year+1900,
p_tm->tm_mon+1,
p_tm->tm_mday) ;
fp=fopen(log_file,"at") ;
if(fp==(FILE *)0)
{
fprintf(stderr,"mig_err_log():can't open the file %s !\n",log_file);
return ;
}
fprintf(fp,"%.2d/%.2d/%4d %.2d:%.2d:%.2d ",
p_tm->tm_mon+1,\
p_tm->tm_mday,\
p_tm->tm_year+1900,\
p_tm->tm_hour,\
p_tm->tm_min,\
p_tm->tm_sec) ;
vfprintf(fp,fmt,ap) ;
fclose(fp) ;
}
这个就是写日志的函数
你这样调用:mig_log("日志开始[%s]->[%d]\n",__FILE__,__LINE__) ;
mig_log("日志开始!\n")都可以的
取消
评论