分享一个日志函数

来源:互联网 发布:斐讯 返现 知乎 编辑:程序博客网 时间:2024/04/29 18:20
#include <stdio.h>
#include <stdarg.h>

void logTest(const char* content, ...)
{
    FILE* logfile = fopen("log.txt", "a");
    if(logfile)
    {
        fprintf(logfile, "########## NEW LOG ########\n");   
    
        va_list arg;
        va_start(arg, content);
        vfprintf(logfile, content, arg);
        va_end(arg);
    
        int status = fflush(logfile);

        fclose(logfile);
    }
}
原创粉丝点击