32 {
33 static DWORD currentFileNumber = 0;
34 static HANDLE hFile = INVALID_HANDLE_VALUE;
35
36 std::wstring fullPath;
38
39
41 std::wcerr << L"Failed to create log directory" << std::endl;
42 return;
43 }
44
45 if (hFile == INVALID_HANDLE_VALUE || GetFileSize(hFile, NULL) >=
MAX_FILE_SIZE) {
46 if (hFile != INVALID_HANDLE_VALUE) {
47 CloseHandle(hFile);
48 currentFileNumber++;
49 }
50
51 std::wostringstream oss;
53 if (currentFileNumber > 0) {
54 oss << currentFileNumber;
55 }
57 fullPath = oss.str();
58
59 hFile = CreateFileW(
60 fullPath.c_str(),
61 FILE_APPEND_DATA,
62 FILE_SHARE_READ,
63 NULL,
64 OPEN_ALWAYS,
65 FILE_ATTRIBUTE_NORMAL,
66 NULL
67 );
68
69 if (hFile == INVALID_HANDLE_VALUE) {
70 std::wcerr << L"Failed to open log file: " << fullPath << std::endl;
71 return;
72 }
73
74
75 SetFilePointer(hFile, 0, NULL, FILE_END);
76 }
77
78 if (!WriteFile(hFile, message.c_str(), message.length() * sizeof(char), &bytesWritten, NULL)) {
79 std::wcerr << L"Failed to write to log file" << std::endl;
80 }
81}
bool EnsureDirectoryExists(const std::wstring &path)