//----------------------------------------------------------------------------- void DebugLog (char* pszFormat, ...) //----------------------------------------------------------------------------- { if (!g_fDebug) return; // Variables needed for debug log output va_list vaArgList; char szOutputString[5000]; int iLenTimestamp = 0; time_t tTime; struct tm *ptmStruct; #if 0 FILE* fp = fopen (g_pszDebugLog, "a"); if (!fp) { printf ("DebugLog(): could not write to '%s'", g_pszDebugLog); return; } #else FILE* fp = stdout; #endif // Get the timestamp tTime = time(NULL); ptmStruct = localtime (&tTime); strftime (szOutputString, 13+1, "%a %H:%M:%S | ", ptmStruct); iLenTimestamp = strlen (szOutputString); // Format the string va_start (vaArgList, pszFormat); vsprintf (szOutputString+iLenTimestamp, pszFormat, vaArgList); va_end (vaArgList); // Send the string to the debug log fprintf (fp, szOutputString); if (!strchr (szOutputString, '\n')) fprintf (fp, "\n"); if ((fp != stdout) && (fp != stderr)) fclose (fp); else fflush (fp); } // DebugLog //----------------------------------------------------------------------------- void ErrorLog (char* pszFormat, ...) //----------------------------------------------------------------------------- { // Variables needed for debug log output va_list vaArgList; char szOutputString [5000]; int iLenTimestamp = 0; time_t tTime; struct tm *ptmStruct; FILE* fp = fopen (g_pszErrorLog, "a"); if (!fp) { ErrorLog ("could not write to '%s'", g_pszErrorLog); return; } // Get the timestamp tTime = time(NULL); ptmStruct = localtime (&tTime); strftime (szOutputString, 13+1, "%a %H:%M:%S | ", ptmStruct); iLenTimestamp = strlen (szOutputString); // Format the string va_start (vaArgList, pszFormat); vsprintf (szOutputString+iLenTimestamp, pszFormat, vaArgList); va_end (vaArgList); // Send the string to the debug log fprintf (fp, szOutputString); fflush (fp); fclose (fp); } // ErrorLog