4 // Originally by David Raingeard (Cal2)
5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups/new stuff by James Hammons
7 // (C) 2010 Underground Software
9 // JLH = James Hammons <jlhamm@acm.org>
12 // --- ---------- -------------------------------------------------------------
13 // JLH 01/16/2010 Created this log ;-)
14 // JLH 07/11/2011 Instead of dumping out on max log file size being reached, we
15 // now just silently ignore any more output. 10 megs ought to be
16 // enough for anybody. ;-) Except when it isn't. :-P
25 //#define MAX_LOG_SIZE 10000000 // Maximum size of log file (10 MB)
26 #define MAX_LOG_SIZE 100000000 // Maximum size of log file (100 MB)
28 static FILE * log_stream = NULL;
29 static uint32 logSize = 0;
31 int LogInit(const char * path)
33 log_stream = fopen(path, "w");
35 if (log_stream == NULL)
48 if (log_stream != NULL)
53 // This logger is used mainly to ensure that text gets written to the log file
54 // even if the program crashes. The performance hit is acceptable in this case!
56 void WriteLog(const char * text, ...)
61 if (log_stream == NULL)
67 logSize += vfprintf(log_stream, text, arg);
69 if (logSize > MAX_LOG_SIZE)
71 // Instead of dumping out, we just close the file and ignore any more output.
78 fflush(log_stream); // Make sure that text is written!