#include <stdio.h>
#include <stdarg.h>

#ifdef LOG_FILE

#define FILENAME "/tmp/1.log"
static int first = 1;
static FILE *log_fd=NULL;

void logf(char *fmt, ...)
{
    	va_list args;
    	char str[1024] ;

	if (first==1) {
		log_fd = fopen(FILENAME,"w");
		first = 0;
	}
	else {
		log_fd=fopen(FILENAME,"a+");
	}
	va_start(args, fmt);
	if (log_fd!=NULL){
		(void) vsprintf(str, fmt, args);
        	fprintf(log_fd, str) ;
	}
    	va_end(args);
    	fclose(log_fd);
    	return ;
}
#else /* LOG_FILE */

#ifdef LOG_STDERR

static FILE *log_fd=stderr;
void logf(char *fmt, ...)
{
    	va_list args;
    	char str[1024] ;

	va_start(args);
	if (log_fd!=NULL){
		(void) vsprintf(str, fmt, args);
        	fprintf(log_fd, str) ;
	}
    	va_end(args);
    	return ;
}

#else  /* LOG_STDERR */

void logf(char *fmt, ...)
{
}

#endif /* LOG_STDERR */
#endif /* LOG_FILE */
