daylog.c

来自「API」· C语言 代码 · 共 58 行

C
58
字号
#include <stdio.h>
#include <varargs.h>
#include "mytools.h"

int daylog(file, line, type, format, va_alist)
    char *file;
    int line;
    int type;
    char *format;
    va_dcl
{
    va_list args;
    char path[80], date[11], time[9];
    char t_day[5];
    FILE *fp;

#ifdef wyz020502_mod
    strcpy(path, (char *)getfname("WORKDIR", DAYFILE));
#else
    getdatef(date, "");
    strcpy(t_day, date+4);
#ifdef Wubin20020829_mod
    sprintf(path, "%s/%s.%s", getenv("WORKDIR"), DAYFILE, t_day);
#else
    sprintf(path, "%s%s.%s", getenv("WORKDIR"), DAYFILE, t_day);
#endif
#endif
    fp = fopen(path, "a");
    if (fp == NULL) {
	errcall(ERROR, "Access daylog file [%s] error!", path);
	return(-1);
    }
    switch (type) {
	case E_WARN:
	    strcpy(path, "WARN ");
	    break;
	case E_ERROR:
	    strcpy(path, "ERROR");
	    break;
	case E_DEBUG:
	    strcpy(path, "DEBUG");
	    break;
    }
#ifdef wyz020504_mod
    fprintf(fp, "%s %s %s %s(%d) : ", date+5, time, path, file, line);
#else
    getdatef(date, "/");
    gettimef(time, ":");
    fprintf(fp, "%s %s %s(%d) : ", date+5, time, file, line);
#endif
    va_start(args);
    vfprintf(fp, format, args);
    va_end(args);
    fprintf(fp, "\n");
    fclose(fp);
    return (0);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?