]> Shamusworld >> Repos - stargem2/blob - src/log.cpp
Fixed the dreaded demo failing bug! HUZZAH! Turned out to be an IRQ line
[stargem2] / src / log.cpp
1 //
2 // Log handler
3 //
4 // by James L. Hammons
5 //
6
7 #include "types.h"
8 #include "log.h"
9
10 #define MAX_LOG_SIZE            10000000                                // Maximum size of log file (10 MB)
11
12 static FILE * log_stream = NULL;
13 static uint32 logSize = 0;
14
15 bool InitLog(const char * path)
16 {
17         log_stream = fopen(path, "wrt");
18
19         if (log_stream == NULL)
20                 return false;
21
22         return true;
23 }
24
25 void LogDone(void)
26 {
27         if (log_stream)
28                 fclose(log_stream);
29 }
30
31 //
32 // This logger is used mainly to ensure that text gets written to the log file
33 // even if the program crashes. The performance hit is acceptable in this case!
34 //
35 void WriteLog(const char * text, ...)
36 {
37         if (!log_stream)
38                 return;
39
40         va_list arg;
41
42         va_start(arg, text);
43         logSize += vfprintf(log_stream, text, arg);
44
45         if (logSize > MAX_LOG_SIZE)
46         {
47                 fflush(log_stream);
48                 fclose(log_stream);
49                 exit(1);
50         }//*/
51
52         va_end(arg);
53         fflush(log_stream);                                     // Make sure that text is written!
54 }