00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00027 #include <sys/types.h>
00028 #include <sys/timeb.h>
00029 #include <time.h>
00030 #include <string.h>
00031 #include "../Include/LogFile.h"
00032
00033
00034
00035
00036
00037 CLogFile::CLogFile (const char* filename, const char* mode)
00038 {
00039
00040 f = fopen (filename, mode);
00041 }
00042
00043
00044
00045
00046
00047 CLogFile::~CLogFile (void)
00048 {
00049
00050 if (f) {
00051 fclose (f);
00052 f = NULL;
00053 }
00054 }
00055
00056
00057
00058
00059 FILE *CLogFile::GetFile (void)
00060 {
00061 return f;
00062 }
00063
00064
00065
00066
00067 void CLogFile::Write (const char* fmt, ...)
00068 {
00069 if (f) {
00070
00071
00072 int nChars = strlen(fmt) + 40;
00073 char *newfmt = new char[nChars];
00074
00075
00076 struct timeb t;
00077 ftime (&t);
00078 struct tm* local = localtime (&t.time);
00079 if (local) {
00080 sprintf (newfmt, "%04d-%02d-%02d %02d:%02d:%02d.%03d %s\n",
00081 1900 + local->tm_year, local->tm_mon+1, local->tm_mday,
00082 local->tm_hour, local->tm_min, local->tm_sec, t.millitm, fmt);
00083 } else {
00084 strcpy (newfmt, fmt);
00085 }
00086
00087 va_list argp;
00088 va_start(argp, fmt);
00089 vfprintf(f, newfmt, argp);
00090 va_end(argp);
00091
00092 delete newfmt;
00093 }
00094 fflush (f);
00095 }
00096