• fs_log


    #include "fs_log.h"
    
    void write_log (const char *format, ...)
    {
        va_list arg;
        int done;
        time_t time_log;
        struct tm* tm_log;
        FILE* pFile = NULL;
    #if LOG_HAVE_WINDOW_OUT
        char buff[300];
        int off = 0;
    #endif
        va_start (arg, format);
    
        time_log = time(NULL);
        tm_log = localtime(&time_log);
    
        pFile = fopen(LOG_FILE, "a");
    
        fprintf(pFile,"%04d-%02d-%02d %02d:%02d:%02d :",
            tm_log->tm_year + 1900, tm_log->tm_mon + 1, tm_log->tm_mday,
            tm_log->tm_hour, tm_log->tm_min, tm_log->tm_sec);
        done = vfprintf (pFile, format, arg);
        va_end (arg);
        fflush(pFile);
    
        fclose(pFile);
    
    #if LOG_HAVE_WINDOW_OUT
        memset(buff, 0, sizeof(buff));
        off = sprintf(buff, "%04d-%02d-%02d %02d:%02d:%02d [%s][%d]:",
            tm_log->tm_year + 1900, tm_log->tm_mon + 1, tm_log->tm_mday,
            tm_log->tm_hour, tm_log->tm_min, tm_log->tm_sec);
        sprintf(buff+off, format, arg);
        printf("%s",buff);
    #endif
    
        return;
    }
    
    void write_log_cond(char valve, char *file_nameconst, int len, char *format, ...)
    {
        va_list arg;
        int done;
        time_t time_log;
        struct tm* tm_log;
        FILE* pFile = NULL;
    #if LOG_HAVE_WINDOW_OUT
        char buff[300];
        int off = 0;
    #endif
    
        if (valve == 0)
        {
            return;
        }
        va_start (arg, format);
    
        time_log = time(NULL);
        tm_log = localtime(&time_log);
    
        pFile = fopen(LOG_FILE, "a");
    
        fprintf(pFile,"%04d-%02d-%02d %02d:%02d:%02d [%s][%d]:",
            tm_log->tm_year + 1900, tm_log->tm_mon + 1, tm_log->tm_mday,
            tm_log->tm_hour, tm_log->tm_min, tm_log->tm_sec,
            file_nameconst,len);
        done = vfprintf (pFile, format, arg);
        va_end (arg);
        fflush(pFile);
    
        fclose(pFile);
    
    #if LOG_HAVE_WINDOW_OUT
        memset(buff, 0, sizeof(buff));
        off = sprintf(buff, "%04d-%02d-%02d %02d:%02d:%02d [%s][%d]:",
            tm_log->tm_year + 1900, tm_log->tm_mon + 1, tm_log->tm_mday,
            tm_log->tm_hour, tm_log->tm_min, tm_log->tm_sec,
            file_nameconst,len);
        sprintf(buff+off, format, arg);
        printf("%s",buff);
    #endif
    
        return;
    }
    fs_log.h
    #include <stdio.h>
    #include <stdarg.h>
    #include <string.h>
    #include <time.h>
    
    #define LOG_FILE "./runlog.txt"
    #define LOG_HAVE_WINDOW_OUT     (1)
    
    #define SHORT_FILE strrchr(__FILE__, '\') ? strrchr(__FILE__, '\') + 1 : __FILE__
    #define LOG_DEBUG_SET_LEVLE(a)  (a),(SHORT_FILE),(__LINE__)
    
    #define print_deb    write_log
    #define print_info    write_log
    #define print_war    write_log
    #define print_err    write_log
    #define print_cond    write_log_cond
    
    extern void write_log (const char *format, ...);
    extern void write_log_cond (char valve, char *file_nameconst, int len, char *format, ...);
    
    #endif
    fs_log.h
  • 相关阅读:
    Scrum框架及其背后的原则(上)——Scrum 框架的伪代码描述[转载自InfoQ]
    用程序给闺女出算数题——我的头脑体操
    敏捷实践调查结果[翻译转载]
    一.初识Selenium
    二.Selenium安装相关文件
    Review of American Beauty(unoriginal)
    三.Selenium IDE学习
    将Java Project转变为Dynamic Web Project
    功能自动化工具watiJ(转载)
    Selenium前奏
  • 原文地址:https://www.cnblogs.com/mrsandstorm/p/9565854.html
Copyright © 2020-2023  润新知