JD2022-TU1/main/extern/ITNetwork/gear/private/tools/GearRemoteFileSystem/logfile.h

59 lines
1.1 KiB
C++

#ifndef GEAR_RFS_LOGFILE_H
#define GEAR_RFS_LOGFILE_H
#include <stdio.h>
#include <string.h>
#include "time.h"
class LogFile
{
public:
LogFile(const char* filename)
{
char tmp[400];
GetModuleFileName(0, tmp, sizeof(tmp));
char* end = strrchr(tmp, '\\');
if (end)
end[1]=0;
else
strcpy(tmp, ".\\");
strcat(tmp, filename);
m_file = fopen(tmp, "w");
}
~LogFile()
{
if (m_file)
fclose(m_file);
}
void Write(const char* str)
{
if (m_file)
{
char timeStr[16];
char dateStr[16];
_strdate(dateStr);
_strtime(timeStr);
fprintf(m_file, "%s %s ", dateStr, timeStr);
fprintf(m_file, "%s", str);
fflush(m_file);
}
}
void WriteF(const char *szFormat, ...)
{
va_list argList;
char szBuffer[1024];
va_start(argList, szFormat);
_vsnprintf(szBuffer, sizeof(szBuffer), szFormat, argList);
va_end(argList);
Write(szBuffer);
}
FILE* m_file;
};
#endif