X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flog.cpp;h=6994cc5ac1d1649838e7938fdc052e8a0437c4b1;hb=f36d026c7b8b398b88765ec5b67a3c767fe5fbad;hp=98c6658d0835cab46464f7f3369ac7dcd2ee7395;hpb=eeb2935c12ef41a63049126748c2574b324403a5;p=apple2 diff --git a/src/log.cpp b/src/log.cpp old mode 100755 new mode 100644 index 98c6658..6994cc5 --- a/src/log.cpp +++ b/src/log.cpp @@ -1,65 +1,69 @@ -// -// Log handler -// -// by James L. Hammons -// (C) 2006 Underground Software -// -// JLH = James L. Hammons -// -// WHO WHEN WHAT -// --- ---------- ------------------------------------------------------------ -// JLH 01/03/2006 Moved includes out of header file for faster compilation -// - -#include "log.h" - -#include -#include -#include -#include "types.h" - -#define MAX_LOG_SIZE 10000000 // Maximum size of log file (10 MB) - -static FILE * log_stream = NULL; -static uint32 logSize = 0; - -bool InitLog(char * path) -{ - log_stream = fopen(path, "wrt"); - - if (log_stream == NULL) - return false; - - 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! -// -void WriteLog(const char * text, ...) -{ - if (!log_stream) - return; - - va_list arg; - - va_start(arg, text); - logSize += vfprintf(log_stream, text, arg); - - 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 handler +// +// by James Hammons +// (C) 2006 Underground Software +// +// JLH = James Hammons +// +// WHO WHEN WHAT +// --- ---------- ------------------------------------------------------------ +// JLH 01/03/2006 Moved includes out of header file for faster compilation +// + +#include "log.h" + +#include +#include +#include +#include + +// 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_t logSize = 0; + + +bool InitLog(const char * path) +{ + log_stream = fopen(path, "wrt"); + + if (log_stream == NULL) + return false; + + 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! +// +void WriteLog(const char * text, ...) +{ + if (!log_stream) + return; + + va_list arg; + + 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) + { + fclose(log_stream); + log_stream = NULL; + } +} +