Back to index

im-sdk  12.3.91
logf.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdarg.h>
00003 
00004 #ifdef LOG_FILE
00005 
00006 #define FILENAME "/tmp/1.log"
00007 static int first = 1;
00008 static FILE *log_fd=NULL;
00009 
00010 void logf(char *fmt, ...)
00011 {
00012        va_list args;
00013        char str[1024] ;
00014 
00015        if (first==1) {
00016               log_fd = fopen(FILENAME,"w");
00017               first = 0;
00018        }
00019        else {
00020               log_fd=fopen(FILENAME,"a+");
00021        }
00022        va_start(args, fmt);
00023        if (log_fd!=NULL){
00024               (void) vsprintf(str, fmt, args);
00025               fprintf(log_fd, str) ;
00026        }
00027        va_end(args);
00028        fclose(log_fd);
00029        return ;
00030 }
00031 #else /* LOG_FILE */
00032 
00033 #ifdef LOG_STDERR
00034 
00035 static FILE *log_fd=stderr;
00036 void logf(char *fmt, ...)
00037 {
00038        va_list args;
00039        char str[1024] ;
00040 
00041        va_start(args);
00042        if (log_fd!=NULL){
00043               (void) vsprintf(str, fmt, args);
00044               fprintf(log_fd, str) ;
00045        }
00046        va_end(args);
00047        return ;
00048 }
00049 
00050 #else  /* LOG_STDERR */
00051 
00052 void logf(char *fmt, ...)
00053 {
00054 }
00055 
00056 #endif /* LOG_STDERR */
00057 #endif /* LOG_FILE */