summaryrefslogtreecommitdiff
path: root/server/src/logging.c
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/logging.c')
-rw-r--r--server/src/logging.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/server/src/logging.c b/server/src/logging.c
index 9084baf..66f1661 100644
--- a/server/src/logging.c
+++ b/server/src/logging.c
@@ -1,6 +1,8 @@
#include <logging.h>
#include <stdio.h>
#include <pthread.h>
+#include <time.h>
+#include <string.h>
static const char *severe = "SEVERE";
static const char *warn = "WARN";
@@ -16,26 +18,33 @@ int init_logging(FILE *out_file) {
}
int vlog_msg(int level, const char *fmt, va_list args) {
+ time_t rawtime;
+ time(&rawtime);
+ char timestr[1024];
+ ctime_r(&rawtime, timestr);
+ timestr[strlen(timestr)-1] = '\0';
+
char output[1024];
int ret = 0;
switch (level) {
case LOG_SEVERE:
- snprintf(output, 1024, "%s: %s", severe, fmt);
+ snprintf(output, 1024, "%s %s: %s", timestr, severe, fmt);
ret = vfprintf(out_stream, output, args);
break;
case LOG_WARNING:
- snprintf(output, 1024, "%s: %s", warn, fmt);
+ snprintf(output, 1024, "%s %s: %s", timestr, warn, fmt);
ret = vfprintf(out_stream, output, args);
break;
case LOG_INFO:
- snprintf(output, 1024, "%s: %s", info, fmt);
+ snprintf(output, 1024, "%s %s: %s", timestr, info, fmt);
ret = vfprintf(out_stream, output, args);
break;
case LOG_DEBUG:
- snprintf(output, 1024, "%s: %s", debug, fmt);
+ snprintf(output, 1024, "%s %s: %s", timestr, debug, fmt);
ret = vfprintf(out_stream, output, args);
break;
}
+ fflush(out_stream);
return ret;
}
@@ -49,3 +58,7 @@ int log_msg(int level, const char *fmt, ...) {
return done;
}
+
+void close_logfile(void) {
+ fclose(out_stream);
+}