diff --git a/src/log.c b/src/log.c index bf403bd..15e7109 100644 --- a/src/log.c +++ b/src/log.c @@ -35,7 +35,7 @@ FILE *output; void TNFSMSGLOG(Header *hdr, const char *msg, ...) { - log_time(); + log_time(output); unsigned char *ip = (unsigned char *)&hdr->ipaddr; char buff[128]; @@ -52,7 +52,7 @@ void TNFSMSGLOG(Header *hdr, const char *msg, ...) void USGLOG(Header *hdr, const char *msg, ...) { - log_time(); + log_time(stdout); unsigned char *ip = (unsigned char *)&hdr->ipaddr; char buff[128]; @@ -70,13 +70,13 @@ void USGLOG(Header *hdr, const char *msg, ...) vsnprintf(buff, sizeof(buff), msg, vargs); va_end(vargs); - fprintf(output, "%s|%d.%d.%d.%d|SID=%02x|%s\n", sdate, ip[0], ip[1], ip[2], ip[3], hdr->sid, buff); - fflush(output); + fprintf(stdout, "%s|%d.%d.%d.%d|SID=%02x|%s\n", sdate, ip[0], ip[1], ip[2], ip[3], hdr->sid, buff); + fflush(stdout); } void MSGLOG(in_addr_t ipaddr, const char *msg, ...) { - log_time(); + log_time(output); unsigned char *ip = (unsigned char *)&ipaddr; char buff[128]; @@ -93,7 +93,7 @@ void MSGLOG(in_addr_t ipaddr, const char *msg, ...) void LOG(const char *msg, ...) { - log_time(); + log_time(output); va_list vargs; va_start(vargs, msg); @@ -103,28 +103,28 @@ void LOG(const char *msg, ...) fflush(output); } -void log_time() { +void log_time(FILE *outf) { time_t now; struct tm *gmt; time(&now); gmt = gmtime(&now); if (gmt == NULL) { - fprintf(output, "Failed to convert time to GMT.\n"); + fprintf(outf, "Failed to convert time to GMT.\n"); return; } char formatted_time[sizeof "2011-10-08T07:07:09Z"]; // Replace %F and %T with equivalents for broader compatibility (wasn't working in MinGW) if (strftime(formatted_time, sizeof formatted_time, "%Y-%m-%dT%H:%M:%SZ", gmt) == 0) { - fprintf(output, "[??] "); + fprintf(outf, "[??] "); return; } - fprintf(output, "[%s] ", formatted_time); + fprintf(outf, "[%s] ", formatted_time); } void log_init(FILE *log_output) { output = log_output; -} \ No newline at end of file +} diff --git a/src/log.h b/src/log.h index 10907d9..d636f98 100644 --- a/src/log.h +++ b/src/log.h @@ -35,6 +35,6 @@ void TNFSMSGLOG(Header *hdr, const char *msg, ...); void USGLOG(Header *hdr, const char *msg, ...); void MSGLOG(in_addr_t ipaddr, const char *msg, ...); void LOG(const char *msg, ...); -void log_time(); +void log_time(FILE *outf); #endif