如何简单创建日志文件

标题:如何创建简单的日志文件

问1:为何要创建日志文件:

答1:在项目代码中,常常需要查看日志文件的信息,来调试CODE

问2:怎么创建一个简单的日志文件

答2:需要如下步骤

  •    FILE *DFile;
       // open log file and print time stamp
       DFile = fopen("log.txt","a+");
       if(DFile == NULL)
       {
          printf("ERROR, Could not open LOT.TXT log file!\n");
          exit(1);
       }


  • //--------------------------------------------------------------------------
    // Debug printf to opened file DFile with a force flush 
    //
    // Return: number of characters printed
    //
    int dprintf(char *format, ...)
    {
       int rt;
       va_list ap;
    
       if (DFile != NULL)
       {
          va_start(ap, format);
          rt = vfprintf(DFile,format,ap); 
          va_end(ap);
    
          fflush(DFile);
       }
    
       va_start(ap, format);
       rt = vfprintf(stdout,format,ap); 
       va_end(ap);
    
       return rt;
    }

  • <pre name="code" class="cpp"> dprintf("hello,world!\n");
    

     
    
    

问3:如何创建一个更好日志文件,包括时间,函数名,哪一个文件,具体哪一行

答3:详情见下篇






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值