免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1424 | 回复: 0
打印 上一主题 下一主题

[C] proc 中报文日志记录问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-05-31 22:42 |只看该作者 |倒序浏览
大家帮忙看一下一个日志记录的问题,过一段时间以后打印就出问题,时间间隔一般在10个小时左右,大家帮忙分析看看
etsDebug(0, "调用createL2ServiceCom 建立监听失败[%d]", -1);



void etsDebug(int class, const char *fmt, ...)
{
   char buf[20000];
   char fname1[128],buf1[32],aCmdbuf[128];
   va_list  args;
   struct stat sbuf;
   int rc;
   char buf2[32];
   char        aNewFile[128];
   struct timeval curtime; /*for get usec*/
   
   if (etsInitDebug()!=0)
     return;

   if ( class <= cgDebug ) {
      memset(buf,0x00,sizeof(buf));
      memset(buf1,0x00,sizeof(buf1));
      memset(buf2,0x00,sizeof(buf2));
      //memset(fname1,0x00,sizeof(fname1));
   
      va_start(args,fmt);
      vsprintf(buf, fmt, args);
      va_end(args);
      
      /*sprintf(fname1,"%s/jigang/debug/%s",getenv("HOME"),agDebugfile);

      rc=stat(fname1, &sbuf);
      if (rc ==0 && sbuf.st_size > 8388608L) {
         GetFormatTime(buf1,sizeof(buf1),"%m%d%H%M");
         sprintf(aNewFile,"%s.%s",fname1,buf1);
         rc = rename(fname1,aNewFile);
         if (rc)
            return;
      }

      if (( fp = fopen(fname1,"a+")) == NULL)
         return;
      */

      GetFormatTime(buf1,sizeof(buf1),"%m-%d %H:%M:%S");
      gettimeofday(&curtime,NULL);        /*get time at usec level*/

      fprintf(fpDebug,"%s:%03d pid[%d]: %s\n",buf1,curtime.tv_usec/1000,getpid(),buf);
      printf("%s:%03d pid[%d]: %s\n",buf1,curtime.tv_usec/1000,getpid(),buf);
      //fclose(fp);
      fflush(fpDebug);
   }
}


int etsInitDebug()
{
         struct stat sbuf;
   char fname1[128],buf1[32];
   char        aNewFile[128];
          
   memset(fname1,0x00,sizeof(fname1));          
         sprintf(fname1,"./debug/%s", "jgComWork_log");
         //sprintf(fname1,"./debug/%s",getenv("HOME"),agDebugfile);
       
   int rc=stat(fname1, &sbuf);
   if (rc ==0 && sbuf.st_size > 8388608L) {
            if (fpDebug)
            {
              fclose(fpDebug);
              fpDebug=NULL;
             }
     GetFormatTime(buf1,sizeof(buf1),"%m%d%H%M");
     sprintf(aNewFile,"%s.%s",fname1,buf1);
     rc = rename(fname1,aNewFile);
     if (rc)
         return -1;
   }
   
   if (fpDebug==NULL)
      fpDebug = fopen(fname1,"a+");
   
   return fpDebug==NULL;
   
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP