zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    uva10129 PlayOnWords(并查集,欧拉回路)
    UVA439 knightMoves (A*启发搜索)
    uva297 Quadtrees (线段树思想,区间操作)
    [uva]AncientMessages象形文字识别 (dfs求连通块)
    [uva816]AbbottsRevenge Abbott的复仇(经典迷宫BFS)
    [dp][uestc]L
    [dp][uestc oj]J
    [uestc oj]H
    [dp uestc oj] G
    [dp]uestc oj 邱老师看电影
  • 原文地址:https://www.cnblogs.com/mrsandstorm/p/9565854.html
Copyright © 2011-2022 走看看