Go to the documentation of this file.00001
00010 #include "log_printf.h"
00011 #include "DetectOS.h"
00012 #include <string>
00013 #include <cstdio>
00014 #include <cstdarg>
00015
00016 using namespace std;
00017
00018
00019 namespace
00020 {
00021 string log_file_ = "error_log.txt";
00022 }
00023
00024
00025 int qrk::log_printf(const char *format, ...)
00026 {
00027 static FILE* fd = NULL;
00028 if (fd == NULL) {
00029 fd = fopen(log_file_.c_str(), "w");
00030 if (fd == NULL) {
00031 return -1;
00032 }
00033 }
00034
00035 va_list ap;
00036
00037
00038 va_start(ap, format);
00039 vfprintf(stderr, format, ap);
00040 va_end(ap);
00041
00042
00043 va_start(ap, format);
00044 int ret = vfprintf(fd, format, ap);
00045 va_end(ap);
00046
00047
00048 fflush(fd);
00049
00050 return ret;
00051 }
00052
00053
00054 void qrk::log_setName(const char* file_name)
00055 {
00056 log_file_ = file_name;
00057 }