/* log.cpp - Don Yang (uguu.org) See log.h for macros. 12/21/00 */ #include"global.h" #include"log.h" #include"resource.h" static FILE *LogFile = NULL; /***************************************************************** LogMalloc Log memory allocation (does nothing in release build). */ void *LogMalloc(char *file, int line, size_t size) { #ifndef NODEBUG char text[256]; void *ptr; ptr = malloc(size); sprintf(text, "0x%08x = malloc(%u)", (unsigned int)ptr, size); WriteLog(file, line, text); return ptr; #else return NULL; #endif } // LogMalloc() /******************************************************************* LogFree Log memory release (does nothing in release build). */ void LogFree(char *file, int line, void *ptr) { #ifndef NODEBUG char text[256]; sprintf(text, "free(0x%08x)", (unsigned int)ptr); WriteLog(file, line, text); free(ptr); #endif } // LogFree() /****************************************************************** StartLog Start logging events (does nothing in release build). */ BOOL StartLog(void) { #ifndef NODEBUG if( (LogFile = fopen(LOG_FILE_NAME, "at+")) == NULL ) { if( (LogFile = fopen(LOG_FILE_NAME, "wt+")) == NULL ) return FALSE; } LogMessage(APP_VERSION ": " __TIME__ " " __DATE__); #endif return TRUE; } // StartLog() /******************************************************************* StopLog Stop logging events (does nothing in release build). */ void StopLog(void) { #ifndef NODEBUG if( LogFile != NULL ) { LogMessage("exit.\n"); fclose(LogFile); LogFile = NULL; } #endif } // StopLog() /****************************************************************** WriteLog Log event (does nothing in release build). */ void WriteLog(char *file, int line, char *text) { #ifndef NODEBUG time_t gtime; struct tm *ltime; time(>ime); ltime = localtime(>ime); if( LogFile != NULL && text != NULL ) fprintf(LogFile, "%.24s:%s:%d: %s\n", asctime(ltime), file, line, text); #endif } // WriteLog() /***************************************************************** WriteLogN Log event with numeric parameter (does nothing in release build). */ void WriteLogN(char *file, int line, char *text, int number) { #ifndef NODEBUG char string[256]; sprintf(string, text, number); WriteLog(file, line, string); #endif } // WriteLogN() char *LogObjTime = __TIME__ " " __DATE__; int LogObjLines = __LINE__;