#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
-#include "types.h"
+#include <stdint.h>
-#define MAX_LOG_SIZE 10000000 // Maximum size of log file (10 MB)
+// Maximum size of log file (10 MB ought to be enough for anybody)
+#define MAX_LOG_SIZE 10000000
static FILE * log_stream = NULL;
-static uint32 logSize = 0;
+static uint32_t logSize = 0;
-bool InitLog(char * path)
+
+bool InitLog(const char * path)
{
log_stream = fopen(path, "wrt");
return true;
}
+
void LogDone(void)
{
if (log_stream)
fclose(log_stream);
}
+
//
// This logger is used mainly to ensure that text gets written to the log file
// even if the program crashes. The performance hit is acceptable in this case!
va_start(arg, text);
logSize += vfprintf(log_stream, text, arg);
+ va_end(arg);
+
+ fflush(log_stream); // Make sure that text is written!
if (logSize > MAX_LOG_SIZE)
{
- fflush(log_stream);
fclose(log_stream);
- exit(1);
- }//*/
-
- va_end(arg);
- fflush(log_stream); // Make sure that text is written!
+ log_stream = NULL;
+ }
}
+