#include <ne-utils.h>
#include <assert.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
#include <time.h>
#include "ne-conf.h"
[_N72] = "N72/IOMM",
};
+static FILE *fp = NULL;
+
/**
* @brief Write a log, to a logfile designated by conf
* @param[in] l Loglevel
* @param[in] m Module designation
*/
void logwrite(loglevel l, module m, const char *format, ...) {
- static FILE *fp = NULL;
-
+ va_list args;
time_t ltime;
+ char* time_str;
+
ltime = time(NULL);
- va_list args;
-
if (fp == NULL) {
size_t n = strlen(conf->log_dir) + strlen(logfilename);
char *filename = malloc(n + 1);
- FILE *fp;
- strncpy(filename, conf->log_dir, strlen(conf->log_dir);
+ strncpy(filename, conf->log_dir, strlen(conf->log_dir));
strncat(filename, logfilename, n);
fp = fopen(filename, "a");
assert(fp != NULL);
+ /* asctime() generates a new line; so remove it */
+ time_str = asctime(localtime(<ime));
+ time_str[strlen(time_str) - 1] = '\x00';
+ fprintf(fp, "[%s][%s][%s] ", loglevelstr[l], modulestr[m], time_str);
+
va_start (args, format);
- fprintf(fp, "[%s][%s][%s] " format, loglevelstr[l], modulestr[m],
- asctime(localtime(<ime)), args);
+ vfprintf(fp, format, args);
va_end (args);
}