Added version information to the beginning of the log file.

This commit is contained in:
2023-05-20 14:25:35 +03:00
parent 9dd557311e
commit b58039b4ab
4 changed files with 11 additions and 10 deletions

View File

@@ -11,5 +11,5 @@
#define LOG_TO_FILE(fmt, ...) StringCchPrintfW(debugBuffer, DBUFLEN, fmt, ##__VA_ARGS__); logfile << GetTimeStamp() << debugBuffer << std::endl;
wchar_t* GetTimeStamp();
void OpenLogFile();
void OpenLogFile(const wchar_t[], const wchar_t[]);
void CloseLogFile();

View File

@@ -8,7 +8,7 @@
#define TBUFLEN 32
#define DBUFLEN 256
extern WCHAR szTitle[MAX_LOADSTRING];
//extern WCHAR szTitle[MAX_LOADSTRING];
extern SYSTEMTIME lt;
extern wchar_t debugBuffer[DBUFLEN];

View File

@@ -17,19 +17,21 @@ wchar_t* GetTimeStamp()
return debugTimeBuffer;
}
void OpenLogFile()
void OpenLogFile(const wchar_t appTitle[], const wchar_t appVersion[])
{
WCHAR appTitleVer[MAX_LOADSTRING]{ 0 };
StringCchPrintfW(appTitleVer, MAX_LOADSTRING, L"%s v%s", appTitle, appVersion);
WCHAR lpszPath[MAX_PATH + 1] = { 0 };
DWORD dwPathLength = GetModuleFileNameW(NULL, lpszPath, MAX_PATH);
DWORD dwError = GetLastError();
if (ERROR_INSUFFICIENT_BUFFER == dwError)
{
MessageBoxW(NULL, L"Path to logfile is too long! Working without logging", szTitle, MB_OK | MB_ICONWARNING);
MessageBoxW(NULL, L"Path to logfile is too long! Working without logging", appTitle, MB_OK | MB_ICONWARNING);
return;
}
if (NULL == dwPathLength)
{
MessageBoxW(NULL, L"Can't get module filename! Working without logging", szTitle, MB_OK | MB_ICONWARNING);
MessageBoxW(NULL, L"Can't get module filename! Working without logging", appTitle, MB_OK | MB_ICONWARNING);
return;
}
@@ -47,12 +49,12 @@ void OpenLogFile()
{
logfile << "\xEF\xBB\xBF"; // (0xEF, 0xBB, 0xBF) - UTF-8 BOM
logfile.imbue(std::locale("en-US.utf8"));
logfile << GetTimeStamp() << "[ " << szTitle << " ] Start log." << std::endl;
logfile << GetTimeStamp() << "[ " << appTitleVer << " ] Start log." << std::endl;
logfile << GetTimeStamp() << "Logfile: \"" << log_path.native() << "\"" << std::endl;
}
else
{
MessageBoxW(NULL, L"Can't open logfile! Working without logging", szTitle, MB_OK | MB_ICONWARNING);
MessageBoxW(NULL, L"Can't open logfile! Working without logging", appTitle, MB_OK | MB_ICONWARNING);
}
return;
}
@@ -61,8 +63,7 @@ void CloseLogFile()
{
if (logfile)
{
logfile << GetTimeStamp() << "[ " << szTitle << " ] Stop log." << std::endl;
logfile << GetTimeStamp() << "Stop log." << std::endl;
logfile.close();
}
}

View File

@@ -113,7 +113,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
return FALSE;
}
OpenLogFile();
OpenLogFile(szTitle, TEXT(VERSION_STR));
LOG_TO_FILE(L"Entering the %s() function", TEXT(__FUNCTION__));