From 55299e1d05aace77827ce84f50d3c3c22c77656d Mon Sep 17 00:00:00 2001 From: Archomeda Date: Fri, 1 Jan 2016 15:25:07 +0100 Subject: [PATCH] Improve logging by including filename, line number and function --- src/Config/ConfigFile.cpp | 12 +++--- src/Config/MainConfigFile.cpp | 6 +-- src/Config/MainConfigFile.h | 5 --- src/Devices/Device.cpp | 14 +++---- src/Devices/DeviceCorsair.cpp | 8 ++-- src/Devices/DeviceLightFX.cpp | 24 ++++++------ src/Devices/DeviceLightpack.cpp | 24 ++++++------ src/Devices/DeviceLogitech.cpp | 6 +-- src/Devices/DeviceRazer.cpp | 12 +++--- src/Devices/Proxies/CUESDKProxy.cpp | 1 - src/Devices/Proxies/LightFX2Proxy.cpp | 1 - src/Devices/Proxies/RzChromaSDKProxy.cpp | 1 - src/Games/Game.cpp | 6 +-- src/Games/GameGw2.cpp | 16 ++++---- src/LightFXExports.cpp | 34 ++++++++-------- src/LightFXExtender.cpp | 4 +- src/Managers/ConfigManager.cpp | 4 +- src/Managers/DeviceManager.cpp | 38 +++++++++--------- src/Managers/GameManager.cpp | 10 ++--- src/Managers/TrayManager.cpp | 11 +++--- src/Managers/UpdateManager.cpp | 34 ++++++++-------- src/Utils/Log.cpp | 50 +++++++++++++----------- src/Utils/Log.h | 29 ++++++++++---- tests/Utils/LogTest.cpp | 4 +- 24 files changed, 167 insertions(+), 187 deletions(-) diff --git a/src/Config/ConfigFile.cpp b/src/Config/ConfigFile.cpp index 77c2b4f..b2d3e89 100644 --- a/src/Config/ConfigFile.cpp +++ b/src/Config/ConfigFile.cpp @@ -22,8 +22,6 @@ #include "../Utils/String.h" -#define LOG(logLevel, message) LOG_(logLevel, wstring(L"Config ") + this->GetCurrentFileName() + L" - " + message) - using namespace std; using namespace lightfx::managers; using namespace lightfx::utils; @@ -61,13 +59,13 @@ namespace lightfx { this->Deserialize(data); this->configLoaded = true; - LOG(LogLevel::Info, L"Loaded configuration"); + LOG_INFO(L"Loaded configuration " + fileName); } else { this->configLoaded = false; - LOG(LogLevel::Info, L"No configuration found, using defaults"); + LOG_INFO(L"Configuration " + fileName + L" not found, using defaults"); } } catch (exception& e) { - LOG(LogLevel::Warning, L"Exception while loading configuration: " + string_to_wstring(e.what())); + LOG_WARNING(L"Exception while loading configuration " + fileName + L", using defaults instead: " + string_to_wstring(e.what())); this->configLoaded = false; } } @@ -96,9 +94,9 @@ namespace lightfx { configStream << data; configStream.close(); - LOG(LogLevel::Debug, L"Saved configuration"); + LOG_DEBUG(L"Saved configuration " + fileName); } catch (exception& e) { - LOG(LogLevel::Warning, L"Exception while saving configuration: " + string_to_wstring(e.what())); + LOG_WARNING(L"Exception while saving configuration " + fileName + L", settings not saved: " + string_to_wstring(e.what())); } } diff --git a/src/Config/MainConfigFile.cpp b/src/Config/MainConfigFile.cpp index 3e8e29e..83b37cd 100644 --- a/src/Config/MainConfigFile.cpp +++ b/src/Config/MainConfigFile.cpp @@ -56,6 +56,7 @@ #define CONF_GAMES_GUILDWARS2_TEAMCOLORANIMATION L"TeamColorAnimation" #pragma endregion + using namespace std; using namespace rapidjson; using namespace lightfx::managers; @@ -93,11 +94,6 @@ namespace lightfx { this->LogitechRestoreLightsOnNullEnabled = false; this->LogitechG110WorkaroundEnabled = false; - this->CorsairColorRangeOutMin = 0; - this->CorsairColorRangeOutMax = 255; - this->CorsairColorRangeInMin = 0; - this->CorsairColorRangeInMax = 255; - this->RazerUseWithKeyboard = true; this->RazerUseWithMouse = true; this->RazerUseWithHeadset = true; diff --git a/src/Config/MainConfigFile.h b/src/Config/MainConfigFile.h index 3027fe8..6fa7425 100644 --- a/src/Config/MainConfigFile.h +++ b/src/Config/MainConfigFile.h @@ -48,11 +48,6 @@ namespace lightfx { bool LogitechRestoreLightsOnNullEnabled = false; bool LogitechG110WorkaroundEnabled = false; - int CorsairColorRangeOutMin = 0; - int CorsairColorRangeOutMax = 255; - int CorsairColorRangeInMin = 0; - int CorsairColorRangeInMax = 255; - bool RazerUseWithKeyboard = true; bool RazerUseWithMouse = true; bool RazerUseWithHeadset = true; diff --git a/src/Devices/Device.cpp b/src/Devices/Device.cpp index b985c67..36d2b90 100644 --- a/src/Devices/Device.cpp +++ b/src/Devices/Device.cpp @@ -14,8 +14,6 @@ #include "../Utils/Log.h" -#define LOG(logLevel, message) LOG_(logLevel, wstring(L"Device ") + this->GetDeviceName() + L" - " + message) - using namespace std; using namespace lightfx::managers; using namespace lightfx::timelines; @@ -40,7 +38,7 @@ namespace lightfx { LFXE_API bool Device::Enable() { if (!this->isEnabled) { - LOG(LogLevel::Debug, L"Enabling"); + LOG_DEBUG(L"Enabling " + this->GetDeviceName()); this->isEnabled = true; } return true; @@ -48,7 +46,7 @@ namespace lightfx { LFXE_API bool Device::Disable() { if (this->isEnabled) { - LOG(LogLevel::Debug, L"Disabling"); + LOG_DEBUG(L"Disabling " + this->GetDeviceName()); this->isEnabled = false; } return true; @@ -57,7 +55,7 @@ namespace lightfx { LFXE_API bool Device::Initialize() { if (!this->isInitialized) { - LOG(LogLevel::Debug, L"Initializing"); + LOG_DEBUG(L"Initializing " + this->GetDeviceName()); this->Reset(); this->isInitialized = true; } @@ -67,7 +65,7 @@ namespace lightfx { LFXE_API bool Device::Release() { if (this->isInitialized) { this->Disable(); - LOG(LogLevel::Debug, L"Releasing"); + LOG_DEBUG(L"Releasing " + this->GetDeviceName()); this->isInitialized = false; } return true; @@ -82,7 +80,7 @@ namespace lightfx { this->ActiveTimeline = this->TimelineQueue.front(); this->TimelineQueue.pop(); this->timelineStart = timeTick; - LOG(LogLevel::Debug, L"Performing timeline " + this->ActiveTimeline.ToString()); + LOG_DEBUG(L"Performing timeline on " + this->GetDeviceName() + L": " + this->ActiveTimeline.ToString()); } else { return true; } @@ -92,7 +90,7 @@ namespace lightfx { unsigned long timelineTick = (timeTick - this->timelineStart).count(); vector newColor = this->ActiveTimeline.GetColorAtTime(timelineTick); if (newColor.size() == 0) { - LOG(LogLevel::Warning, L"Timeline has no colors set! Ignoring update"); + LOG_WARNING(L"Timeline has no colors set! Ignoring update for " + this->GetDeviceName()); return true; } bool needsUpdate = this->lightColor.size() != newColor.size(); diff --git a/src/Devices/DeviceCorsair.cpp b/src/Devices/DeviceCorsair.cpp index 571643e..464097f 100644 --- a/src/Devices/DeviceCorsair.cpp +++ b/src/Devices/DeviceCorsair.cpp @@ -16,8 +16,6 @@ #include "../Utils/Log.h" -#define LOG(logLevel, message) LOG_(logLevel, wstring(L"Device ") + this->GetDeviceName() + L" - " + message) - using namespace std; using namespace lightfx::devices::proxies; using namespace lightfx::managers; @@ -33,7 +31,7 @@ namespace lightfx { // Load the library first this->library = unique_ptr(new CUESDKProxy); if (!this->library->Load()) { - LOG(LogLevel::Error, L"Failed to access the CUESDK library"); + LOG_ERROR(L"Failed to access the CUESDK library"); this->SetInitialized(false); return false; } @@ -68,7 +66,7 @@ namespace lightfx { if (Device::Enable()) { this->library->CorsairPerformProtocolHandshake(); if (const auto error = this->library->CorsairGetLastError()) { - LOG(LogLevel::Error, L"Handshake with Corsair failed: " + this->library->CorsairErrorToString(error)); + LOG_ERROR(L"Handshake with Corsair failed: " + this->library->CorsairErrorToString(error)); } else { this->SetEnabled(false); return false; @@ -101,7 +99,7 @@ namespace lightfx { } } - LOG(LogLevel::Debug, L"Update color to (" + to_wstring(updated_red) + L"," + to_wstring(updated_green) + L"," + to_wstring(updated_blue) + L")"); + LOG_DEBUG(L"Update color to (" + to_wstring(updated_red) + L"," + to_wstring(updated_green) + L"," + to_wstring(updated_blue) + L")"); return this->library->CorsairSetLedsColorsAsync(static_cast(vec.size()), vec.data(), nullptr, nullptr); } diff --git a/src/Devices/DeviceLightFX.cpp b/src/Devices/DeviceLightFX.cpp index 5bdff53..e36e6f4 100644 --- a/src/Devices/DeviceLightFX.cpp +++ b/src/Devices/DeviceLightFX.cpp @@ -15,8 +15,6 @@ #include "../Utils/String.h" -#define LOG(logLevel, message) LOG_(logLevel, wstring(L"LightFX Device ") + this->GetDeviceName() + L" - " + message) - using namespace std; using namespace lightfx::devices::proxies; using namespace lightfx::managers; @@ -33,7 +31,7 @@ namespace lightfx { auto config = this->GetManager()->GetLightFXExtender()->GetConfigManager()->GetMainConfig(); this->library = unique_ptr(new LightFX2Proxy(config->AlienwareDllName, config->AlienwareBackupDllName)); if (!this->library->Load()) { - LOG(LogLevel::Error, L"Failed to access the Alienware LightFX library"); + LOG_ERROR(L"Failed to access the Alienware LightFX library"); this->SetInitialized(false); return false; } @@ -46,7 +44,7 @@ namespace lightfx { unsigned char devType = 0; result = this->library->LFX_GetDeviceDescription(this->GetDeviceIndex(), devDesc, LFX_MAX_STRING_SIZE, &devType); if (result != LFX_SUCCESS) { - LOG(LogLevel::Error, L"Couldn't get device description from " + to_wstring(this->GetDeviceIndex()) + L": " + this->library->LfxResultToString(result)); + LOG_ERROR(L"Couldn't get device description from " + to_wstring(this->GetDeviceIndex()) + L": " + this->library->LfxResultToString(result)); LFX_SAFE_DELETE_ARRAY(devDesc); this->SetInitialized(false); return false; @@ -59,12 +57,12 @@ namespace lightfx { unsigned int numLights = 0; result = this->library->LFX_GetNumLights(this->GetDeviceIndex(), &numLights); if (result != LFX_SUCCESS) { - LOG(LogLevel::Error, L"Couldn't get the number of lights from " + to_wstring(this->GetDeviceIndex()) + L": " + this->library->LfxResultToString(result)); + LOG_ERROR(L"Couldn't get the number of lights from " + to_wstring(this->GetDeviceIndex()) + L": " + this->library->LfxResultToString(result)); this->SetInitialized(false); return false; } this->SetNumberOfLights(numLights); - LOG(LogLevel::Debug, to_wstring(numLights) + L" lights available"); + LOG_DEBUG(to_wstring(numLights) + L" lights available"); // Set up lights for (unsigned int i = 0; i < numLights; ++i) { @@ -76,13 +74,13 @@ namespace lightfx { if (result == LFX_SUCCESS) { lightData.Name = string_to_wstring(lightDesc); } else { - LOG(LogLevel::Warning, L"Couldn't get light description " + to_wstring(i) + L" from " + to_wstring(this->GetDeviceIndex()) + L": " + this->library->LfxResultToString(result) + L" (using default)"); + LOG_WARNING(L"Couldn't get light description " + to_wstring(i) + L" from " + to_wstring(this->GetDeviceIndex()) + L": " + this->library->LfxResultToString(result) + L" (using default)"); } LFX_SAFE_DELETE_ARRAY(lightDesc); if (lightData.Name == L"") { lightData.Name = to_wstring(i); } - LOG(LogLevel::Debug, L"Light " + to_wstring(i) + L" name: " + lightData.Name); + LOG_DEBUG(L"Light " + to_wstring(i) + L" name: " + lightData.Name); // Location LFX_POSITION lightLoc; @@ -90,10 +88,10 @@ namespace lightfx { if (result == LFX_SUCCESS) { lightData.Position = { lightLoc.x, lightLoc.y, lightLoc.z }; } else { - LOG(LogLevel::Warning, L"Couldn't get light location " + to_wstring(i) + L" from " + to_wstring(this->GetDeviceIndex()) + L": " + this->library->LfxResultToString(result) + L" (using default)"); + LOG_WARNING(L"Couldn't get light location " + to_wstring(i) + L" from " + to_wstring(this->GetDeviceIndex()) + L": " + this->library->LfxResultToString(result) + L" (using default)"); lightData.Position = { 0, 0, 0 }; } - LOG(LogLevel::Debug, L"Light " + to_wstring(i) + L" pos: (" + to_wstring(lightData.Position.x) + L", " + to_wstring(lightData.Position.y) + L", " + to_wstring(lightData.Position.z) + L")"); + LOG_DEBUG(L"Light " + to_wstring(i) + L" pos: (" + to_wstring(lightData.Position.x) + L", " + to_wstring(lightData.Position.y) + L", " + to_wstring(lightData.Position.z) + L")"); this->SetLightData(i, lightData); } @@ -151,17 +149,17 @@ namespace lightfx { LFX_RESULT result; for (unsigned int i = 0; i < numLights; ++i) { LFX_COLOR color = { colors[i].red, colors[i].green, colors[i].blue, colors[i].brightness }; - LOG(LogLevel::Debug, L"Update color of light " + this->GetLightData(i).Name + L" (" + to_wstring(i) + L") to (" + to_wstring(colors[i].red) + L"," + to_wstring(colors[i].green) + L"," + to_wstring(colors[i].blue) + L")"); + LOG_DEBUG(L"Update color of light " + this->GetLightData(i).Name + L" (" + to_wstring(i) + L") to (" + to_wstring(colors[i].red) + L"," + to_wstring(colors[i].green) + L"," + to_wstring(colors[i].blue) + L")"); result = this->library->LFX_SetLightColor(this->GetDeviceIndex(), i, &color); if (result != LFX_SUCCESS) { - LOG(LogLevel::Warning, L"SetLightColor() failed: " + this->library->LfxResultToString(result)); + LOG_WARNING(L"SetLightColor() failed: " + this->library->LfxResultToString(result)); return false; } } result = this->library->LFX_Update(); if (result != LFX_SUCCESS) { - LOG(LogLevel::Warning, L"Update() failed: " + this->library->LfxResultToString(result)); + LOG_WARNING(L"Update() failed: " + this->library->LfxResultToString(result)); } return result == LFX_SUCCESS; } diff --git a/src/Devices/DeviceLightpack.cpp b/src/Devices/DeviceLightpack.cpp index 81c181f..9271248 100644 --- a/src/Devices/DeviceLightpack.cpp +++ b/src/Devices/DeviceLightpack.cpp @@ -17,8 +17,6 @@ #include "../Utils/String.h" -#define LOG(logLevel, message) LOG_(logLevel, wstring(L"Device ") + this->GetDeviceName() + L" - " + message) - using namespace std; using namespace lightfx::managers; using namespace lightfx::timelines; @@ -41,7 +39,7 @@ namespace lightfx { // Just do an initial pass to check how many LEDs there are available if (this->ConnectAPI()) { int countLeds = this->GetCountLeds(); - LOG(LogLevel::Debug, to_wstring(countLeds) + L" LEDs available"); + LOG_DEBUG(to_wstring(countLeds) + L" LEDs available"); this->SetNumberOfLights(countLeds); auto leds = this->GetLeds(); LightpackScreen screen = this->GetScreenSize(); @@ -52,7 +50,7 @@ namespace lightfx { int posX = int(((leds[i].x - screen.x) + (leds[i].width / 2)) / divider); int posY = int(((screen.height - leds[i].y - screen.y) + (leds[i].height / 2)) / divider); light.Position = { posX, posY, 0 }; - LOG(LogLevel::Debug, L"Get LED " + to_wstring(i) + L" pos: (" + to_wstring(posX) + L"," + to_wstring(posY) + L")"); + LOG_DEBUG(L"Get LED " + to_wstring(i) + L" pos: (" + to_wstring(posX) + L"," + to_wstring(posY) + L")"); this->SetLightData(i, light); } @@ -105,11 +103,11 @@ namespace lightfx { bool DeviceLightpack::ConnectAPI() { - LOG(LogLevel::Debug, L"ConnectAPI()"); + LOG_DEBUG(L"Connecting with API"); WSADATA wsaData; if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { - LOG(LogLevel::Error, L"WSAStartup failed"); + LOG_ERROR(L"WSAStartup failed"); return false; } @@ -121,21 +119,21 @@ namespace lightfx { hints.ai_protocol = IPPROTO_TCP; if (GetAddrInfoW(this->hostname.c_str(), this->port.c_str(), &hints, &result) != 0) { - LOG(LogLevel::Error, L"GetAddrInfoW failed"); + LOG_ERROR(L"GetAddrInfoW failed"); WSACleanup(); return false; } this->lightpackSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol); if (this->lightpackSocket == INVALID_SOCKET) { - LOG(LogLevel::Error, L"Invalid socket"); + LOG_ERROR(L"Invalid socket"); FreeAddrInfoW(result); WSACleanup(); return false; } if (connect(this->lightpackSocket, result->ai_addr, (int)result->ai_addrlen) == SOCKET_ERROR) { - LOG(LogLevel::Error, L"Connection error"); + LOG_ERROR(L"Connection error"); closesocket(this->lightpackSocket); this->lightpackSocket = INVALID_SOCKET; FreeAddrInfoW(result); @@ -157,7 +155,7 @@ namespace lightfx { } bool DeviceLightpack::DisconnectAPI() { - LOG(LogLevel::Debug, L"DisconnectAPI()"); + LOG_DEBUG(L"Disconnecting from API"); this->Unlock(); @@ -174,7 +172,7 @@ namespace lightfx { } bool DeviceLightpack::SendAPI(const wstring& cmd) { - LOG(LogLevel::Debug, L"SendAPI(\"" + cmd + L"\")"); + LOG_DEBUG(L"Send: " + cmd + L""); wstring s = cmd + L"\n"; if (s.length() > (size_t)numeric_limits::max()) { @@ -203,7 +201,7 @@ namespace lightfx { // Error } - LOG(LogLevel::Debug, L"ReceiveAPI(): " + wresult); + LOG_DEBUG(L"Receive: " + wresult); return wresult; } @@ -316,7 +314,7 @@ namespace lightfx { result.height = max(result.height, led.y + led.height); } - LOG(LogLevel::Debug, L"GetScreenSize(): (" + to_wstring(result.x) + L"," + to_wstring(result.y) + L"," + to_wstring(result.width) + L"," + to_wstring(result.height) + L")"); + LOG_DEBUG(L"Screen size: (" + to_wstring(result.x) + L"," + to_wstring(result.y) + L"," + to_wstring(result.width) + L"," + to_wstring(result.height) + L")"); return result; /* diff --git a/src/Devices/DeviceLogitech.cpp b/src/Devices/DeviceLogitech.cpp index bda0829..38ff852 100644 --- a/src/Devices/DeviceLogitech.cpp +++ b/src/Devices/DeviceLogitech.cpp @@ -16,8 +16,6 @@ #include "../Utils/Log.h" -#define LOG(logLevel, message) LOG_(logLevel, wstring(L"Device ") + this->GetDeviceName() + L" - " + message) - using namespace std; using namespace lightfx::managers; using namespace lightfx::timelines; @@ -65,7 +63,7 @@ namespace lightfx { this->Reset(); LogiLedSaveCurrentLighting(); } else { - LOG(LogLevel::Error, L"Could not enable Logitech, make sure that Logitech Gaming Software is running and that it's at least at version 8.57.145"); + LOG_ERROR(L"Could not enable Logitech, make sure that Logitech Gaming Software is running and that it's at least at version 8.57.145"); this->SetEnabled(false); return false; } @@ -113,7 +111,7 @@ namespace lightfx { green = (green - this->rangeOutMin) / divider * brightness + this->rangeInMin; blue = (blue - this->rangeOutMin) / divider * brightness + this->rangeInMin; - LOG(LogLevel::Debug, L"Update color to (" + to_wstring(red) + L"," + to_wstring(green) + L"," + to_wstring(blue) + L")"); + LOG_DEBUG(L"Update color to (" + to_wstring(red) + L"," + to_wstring(green) + L"," + to_wstring(blue) + L")"); return LogiLedSetLighting((int)red, (int)green, (int)blue); } diff --git a/src/Devices/DeviceRazer.cpp b/src/Devices/DeviceRazer.cpp index 14664c6..7aa8851 100644 --- a/src/Devices/DeviceRazer.cpp +++ b/src/Devices/DeviceRazer.cpp @@ -12,8 +12,6 @@ #include "../Utils/Log.h" -#define LOG(logLevel, message) LOG_(logLevel, wstring(L"Device ") + this->GetDeviceName() + L" - " + message) - using namespace std; using namespace lightfx::devices::proxies; using namespace lightfx::managers; @@ -44,7 +42,7 @@ namespace lightfx { // Load the library first this->library = unique_ptr(new RzChromaSDKProxy); if (!this->library->Load()) { - LOG(LogLevel::Error, L"Failed to access the RzChromaSDK library"); + LOG_ERROR(L"Failed to access the RzChromaSDK library"); this->SetInitialized(false); return false; } @@ -98,13 +96,13 @@ namespace lightfx { { this->Reset(); } else { - LOG(LogLevel::Error, L"No known Razer devices connected"); + LOG_ERROR(L"No known Razer devices connected"); this->library->RzUnInit(); this->SetEnabled(false); return false; } } else { - LOG(LogLevel::Error, L"Could not enable Razor device, initialization error: " + this->library->RzResultToString(result)); + LOG_ERROR(L"Could not enable Razor device, initialization error: " + this->library->RzResultToString(result)); this->SetEnabled(false); return false; } @@ -120,7 +118,7 @@ namespace lightfx { if (Device::Disable()) { RZRESULT result = this->library->RzUnInit(); if (result != RZRESULT_SUCCESS) { - LOG(LogLevel::Error, L"Could not disable Razor device, uninitialization error: " + this->library->RzResultToString(result)); + LOG_ERROR(L"Could not disable Razor device, uninitialization error: " + this->library->RzResultToString(result)); this->SetEnabled(true); return false; } @@ -144,7 +142,7 @@ namespace lightfx { COLORREF Color = RGB(updated_red, updated_green, updated_blue); - LOG(LogLevel::Debug, L"Update color to (" + to_wstring(updated_red) + L"," + to_wstring(updated_green) + L"," + to_wstring(updated_blue) + L")"); + LOG_DEBUG(L"Update color to (" + to_wstring(updated_red) + L"," + to_wstring(updated_green) + L"," + to_wstring(updated_blue) + L")"); bool keyboardresult = true; bool mouseresult = true; diff --git a/src/Devices/Proxies/CUESDKProxy.cpp b/src/Devices/Proxies/CUESDKProxy.cpp index 1fb425a..a4d1654 100644 --- a/src/Devices/Proxies/CUESDKProxy.cpp +++ b/src/Devices/Proxies/CUESDKProxy.cpp @@ -7,7 +7,6 @@ using namespace std; - namespace lightfx { namespace devices { namespace proxies { diff --git a/src/Devices/Proxies/LightFX2Proxy.cpp b/src/Devices/Proxies/LightFX2Proxy.cpp index 59ab3e5..e57d1cf 100644 --- a/src/Devices/Proxies/LightFX2Proxy.cpp +++ b/src/Devices/Proxies/LightFX2Proxy.cpp @@ -11,7 +11,6 @@ using namespace std; using namespace lightfx::utils; - namespace lightfx { namespace devices { namespace proxies { diff --git a/src/Devices/Proxies/RzChromaSDKProxy.cpp b/src/Devices/Proxies/RzChromaSDKProxy.cpp index f42ec9e..e066cf2 100644 --- a/src/Devices/Proxies/RzChromaSDKProxy.cpp +++ b/src/Devices/Proxies/RzChromaSDKProxy.cpp @@ -7,7 +7,6 @@ using namespace std; - namespace lightfx { namespace devices { namespace proxies { diff --git a/src/Games/Game.cpp b/src/Games/Game.cpp index 3662c29..ae733a7 100644 --- a/src/Games/Game.cpp +++ b/src/Games/Game.cpp @@ -9,8 +9,6 @@ #include "../Utils/Log.h" -#define LOG(logLevel, message) LOG_(logLevel, wstring(L"Game ") + this->GetGameName() + L" - " + message) - using namespace std; using namespace lightfx::managers; using namespace lightfx::utils; @@ -25,7 +23,7 @@ namespace lightfx { LFXE_API bool Game::Initialize() { if (!this->isInitialized) { - LOG(LogLevel::Debug, L"Initializing"); + LOG_DEBUG(L"Initializing " + this->GetGameName()); this->isInitialized = true; } return true; @@ -33,7 +31,7 @@ namespace lightfx { LFXE_API bool Game::Release() { if (this->isInitialized) { - LOG(LogLevel::Debug, L"Releasing"); + LOG_DEBUG(L"Releasing " + this->GetGameName()); this->isInitialized = false; } return true; diff --git a/src/Games/GameGw2.cpp b/src/Games/GameGw2.cpp index a414b8f..388649e 100644 --- a/src/Games/GameGw2.cpp +++ b/src/Games/GameGw2.cpp @@ -18,8 +18,6 @@ #include "../Utils/Log.h" -#define LOG(logLevel, message) LOG_(logLevel, wstring(L"Game ") + this->GetGameName() + L" - " + message) - using namespace std; using namespace rapidjson; using namespace lightfx::devices; @@ -89,20 +87,20 @@ namespace lightfx { case 9: // Blue startColor = { 29, 118, 169, 0 }; endColor = { 29, 118, 169, 255 }; - LOG(LogLevel::Debug, L"Mumble Link - Detected PvP/WvW blue team"); + LOG_DEBUG(L"Mumble Link - Detected PvP/WvW blue team"); break; case 55: // Green startColor = { 119, 192, 33, 0 }; endColor = { 119, 192, 33, 255 }; - LOG(LogLevel::Debug, L"Mumble Link - Detected PvP/WvW green team"); + LOG_DEBUG(L"Mumble Link - Detected PvP/WvW green team"); break; case 376: // Red startColor = { 203, 28, 36, 0 }; endColor = { 203, 28, 36, 255 }; - LOG(LogLevel::Debug, L"Mumble Link - Detected PvP/WvW red team"); + LOG_DEBUG(L"Mumble Link - Detected PvP/WvW red team"); break; default: // Unknown - LOG(LogLevel::Info, L"Mumble Link - Detected unknown team color: " + to_wstring(teamColorId) + L", skipping"); + LOG_INFO(L"Mumble Link - Detected unknown team color: " + to_wstring(teamColorId) + L", skipping"); return; } @@ -124,7 +122,7 @@ namespace lightfx { if (j < resetColor.size()) { color = resetColor[j]; } else { - LOG(LogLevel::Warning, L"No reset color defined for pulsing team color, using fallback color white"); + LOG_WARNING(L"No reset color defined for pulsing team color, using fallback color white"); } timelines.push_back(LightTimeline::NewPulse(startColor, endColor, color, 200, 5, 100, 400)); } @@ -143,7 +141,7 @@ namespace lightfx { } LFXE_API void GameGw2::MumbleLinkLoop() { - LOG(LogLevel::Debug, L"Mumble Link started"); + LOG_DEBUG(L"Mumble Link started"); while (this->mumbleLinkLoopRunning) { if (this->lastTick != this->mumbleLinkedMem->uiTick) { @@ -164,7 +162,7 @@ namespace lightfx { } } } catch (...) { - LOG(LogLevel::Error, L"Error when parsing Mumble Link identity: " + wstring(identity)); + LOG_ERROR(L"Error when parsing Mumble Link identity: " + wstring(identity)); } } } diff --git a/src/LightFXExports.cpp b/src/LightFXExports.cpp index 6ec5f1f..1e5c2dc 100644 --- a/src/LightFXExports.cpp +++ b/src/LightFXExports.cpp @@ -18,8 +18,6 @@ #include "Utils/String.h" -#define LOG(logLevel, message) LOG_(logLevel, wstring(L"LightFXExports - ") + message) - using namespace std; using namespace lightfx; using namespace lightfx::devices; @@ -73,7 +71,7 @@ extern "C" { return lightFXExtender->GetDeviceManager()->GetChildrenCount() > 0 ? LFX_SUCCESS : LFX_ERROR_NODEVS; } catch (const exception& ex) { - LOG(LogLevel::Error, L"Exception in LFX_Initialize: " + string_to_wstring(ex.what())); + LOG_ERROR(L"Exception in LFX_Initialize: " + string_to_wstring(ex.what())); return LFX_FAILURE; } } @@ -85,7 +83,7 @@ extern "C" { return LFX_SUCCESS; } catch (const exception& ex) { - LOG(LogLevel::Error, L"Exception in LFX_Release: " + string_to_wstring(ex.what())); + LOG_ERROR(L"Exception in LFX_Release: " + string_to_wstring(ex.what())); return LFX_FAILURE; } } @@ -109,7 +107,7 @@ extern "C" { return LFX_SUCCESS; } catch (const exception& ex) { - LOG(LogLevel::Error, L"Exception in LFX_Reset: " + string_to_wstring(ex.what())); + LOG_ERROR(L"Exception in LFX_Reset: " + string_to_wstring(ex.what())); return LFX_FAILURE; } } @@ -130,7 +128,7 @@ extern "C" { return LFX_SUCCESS; } catch (const exception& ex) { - LOG(LogLevel::Error, L"Exception in LFX_Update: " + string_to_wstring(ex.what())); + LOG_ERROR(L"Exception in LFX_Update: " + string_to_wstring(ex.what())); return LFX_FAILURE; } } @@ -159,7 +157,7 @@ extern "C" { return LFX_SUCCESS; } catch (const exception& ex) { - LOG(LogLevel::Error, L"Exception in LFX_GetNumDevices: " + string_to_wstring(ex.what())); + LOG_ERROR(L"Exception in LFX_GetNumDevices: " + string_to_wstring(ex.what())); return LFX_FAILURE; } } @@ -188,7 +186,7 @@ extern "C" { return LFX_SUCCESS; } catch (const exception& ex) { - LOG(LogLevel::Error, L"Exception in LFX_GetDeviceDescription (devIndex=" + to_wstring(devIndex) + L"): " + string_to_wstring(ex.what())); + LOG_ERROR(L"Exception in LFX_GetDeviceDescription (devIndex=" + to_wstring(devIndex) + L"): " + string_to_wstring(ex.what())); return LFX_FAILURE; } } @@ -214,7 +212,7 @@ extern "C" { return LFX_SUCCESS; } catch (const exception& ex) { - LOG(LogLevel::Error, L"Exception in LFX_GetNumLights (devIndex=" + to_wstring(devIndex) + L"): " + string_to_wstring(ex.what())); + LOG_ERROR(L"Exception in LFX_GetNumLights (devIndex=" + to_wstring(devIndex) + L"): " + string_to_wstring(ex.what())); return LFX_FAILURE; } } @@ -246,7 +244,7 @@ extern "C" { return LFX_SUCCESS; } catch (const exception& ex) { - LOG(LogLevel::Error, L"Exception in LFX_GetLightDescription (devIndex=" + to_wstring(devIndex) + L", lightIndex=" + to_wstring(lightIndex) + L"): " + string_to_wstring(ex.what())); + LOG_ERROR(L"Exception in LFX_GetLightDescription (devIndex=" + to_wstring(devIndex) + L", lightIndex=" + to_wstring(lightIndex) + L"): " + string_to_wstring(ex.what())); return LFX_FAILURE; } } @@ -273,7 +271,7 @@ extern "C" { return LFX_SUCCESS; } catch (const exception& ex) { - LOG(LogLevel::Error, L"Exception in LFX_GetLightLocation (devIndex=" + to_wstring(devIndex) + L", lightIndex=" + to_wstring(lightIndex) + L"): " + string_to_wstring(ex.what())); + LOG_ERROR(L"Exception in LFX_GetLightLocation (devIndex=" + to_wstring(devIndex) + L", lightIndex=" + to_wstring(lightIndex) + L"): " + string_to_wstring(ex.what())); return LFX_FAILURE; } } @@ -300,7 +298,7 @@ extern "C" { return LFX_SUCCESS; } catch (const exception& ex) { - LOG(LogLevel::Error, L"Exception in LFX_GetLightColor (devIndex=" + to_wstring(devIndex) + L", lightIndex=" + to_wstring(lightIndex) + L"): " + string_to_wstring(ex.what())); + LOG_ERROR(L"Exception in LFX_GetLightColor (devIndex=" + to_wstring(devIndex) + L", lightIndex=" + to_wstring(lightIndex) + L"): " + string_to_wstring(ex.what())); return LFX_FAILURE; } } @@ -331,7 +329,7 @@ extern "C" { return LFX_SUCCESS; } catch (const exception& ex) { - LOG(LogLevel::Error, L"Exception in LFX_GetLightColor (devIndex=" + to_wstring(devIndex) + L", lightIndex=" + to_wstring(lightIndex) + L"): " + string_to_wstring(ex.what())); + LOG_ERROR(L"Exception in LFX_GetLightColor (devIndex=" + to_wstring(devIndex) + L", lightIndex=" + to_wstring(lightIndex) + L"): " + string_to_wstring(ex.what())); return LFX_FAILURE; } } @@ -355,7 +353,7 @@ extern "C" { return LFX_SUCCESS; } catch (const exception& ex) { - LOG(LogLevel::Error, L"Exception in LFX_Light (locationMask=" + to_wstring(locationMask) + L"): " + string_to_wstring(ex.what())); + LOG_ERROR(L"Exception in LFX_Light (locationMask=" + to_wstring(locationMask) + L"): " + string_to_wstring(ex.what())); return LFX_FAILURE; } } @@ -382,7 +380,7 @@ extern "C" { return LFX_SetLightActionColorEx(devIndex, lightIndex, actionType, &startColor, primaryCol); } catch (const exception& ex) { - LOG(LogLevel::Error, L"Exception in LFX_SetLightActionColor (devIndex=" + to_wstring(devIndex) + L", lightIndex=" + to_wstring(lightIndex) + L", actionType=" + to_wstring(actionType) + L"): " + string_to_wstring(ex.what())); + LOG_ERROR(L"Exception in LFX_SetLightActionColor (devIndex=" + to_wstring(devIndex) + L", lightIndex=" + to_wstring(lightIndex) + L", actionType=" + to_wstring(actionType) + L"): " + string_to_wstring(ex.what())); return LFX_FAILURE; } } @@ -425,7 +423,7 @@ extern "C" { return LFX_SUCCESS; } catch (const exception& ex) { - LOG(LogLevel::Error, L"Exception in LFX_SetLightActionColorEx (devIndex=" + to_wstring(devIndex) + L", lightIndex=" + to_wstring(lightIndex) + L", actionType=" + to_wstring(actionType) + L"): " + string_to_wstring(ex.what())); + LOG_ERROR(L"Exception in LFX_SetLightActionColorEx (devIndex=" + to_wstring(devIndex) + L", lightIndex=" + to_wstring(lightIndex) + L", actionType=" + to_wstring(actionType) + L"): " + string_to_wstring(ex.what())); return LFX_FAILURE; } } @@ -458,7 +456,7 @@ extern "C" { return result; } catch (const exception& ex) { - LOG(LogLevel::Error, L"Exception in LFX_ActionColor (locationMask=" + to_wstring(locationMask) + L", actionType=" + to_wstring(actionType) + L"): " + string_to_wstring(ex.what())); + LOG_ERROR(L"Exception in LFX_ActionColor (locationMask=" + to_wstring(locationMask) + L", actionType=" + to_wstring(actionType) + L"): " + string_to_wstring(ex.what())); return LFX_FAILURE; } } @@ -492,7 +490,7 @@ extern "C" { return result; } catch (const exception& ex) { - LOG(LogLevel::Error, L"Exception in LFX_ActionColorEx (locationMask=" + to_wstring(locationMask) + L", actionType=" + to_wstring(actionType) + L"): " + string_to_wstring(ex.what())); + LOG_ERROR(L"Exception in LFX_ActionColorEx (locationMask=" + to_wstring(locationMask) + L", actionType=" + to_wstring(actionType) + L"): " + string_to_wstring(ex.what())); return LFX_FAILURE; } } diff --git a/src/LightFXExtender.cpp b/src/LightFXExtender.cpp index 3676292..64905e6 100644 --- a/src/LightFXExtender.cpp +++ b/src/LightFXExtender.cpp @@ -54,14 +54,14 @@ namespace lightfx { Log::StartLoggerWorker(); Log::RotateLog(); - LOG_(LogLevel::Info, L"LightFX Extender v" + this->updateManager->GetCurrentVersion().ToString()); + LOG_INFO(L"LightFX Extender v" + this->updateManager->GetCurrentVersion().ToString()); wstring processFileName; wstring ext; wstring processPath = GetProcessName(nullptr, nullptr, &processFileName, &ext); processFileName = processFileName + ext; - LOG_(LogLevel::Info, L"Connected to " + processPath); + LOG_INFO(L"Connected to " + processPath); this->configManager->InitializeConfigs(); Log::SetMinimumLogLevel(this->configManager->GetMainConfig()->MinimumLogLevel); diff --git a/src/Managers/ConfigManager.cpp b/src/Managers/ConfigManager.cpp index d58ab96..ba9bb37 100644 --- a/src/Managers/ConfigManager.cpp +++ b/src/Managers/ConfigManager.cpp @@ -10,8 +10,6 @@ #include "../Utils/Log.h" -#define LOG(logLevel, message) LOG_(logLevel, wstring(L"ConfigManager - ") + message) - using namespace std; using namespace lightfx::config; using namespace lightfx::utils; @@ -24,7 +22,7 @@ namespace lightfx { this->AddChild(L"MainConfig", configFile); configFile->Load(); - LOG(LogLevel::Info, L"Config files loaded"); + LOG_INFO(L"Config files loaded"); return true; } diff --git a/src/Managers/DeviceManager.cpp b/src/Managers/DeviceManager.cpp index dc9d9b9..8eb6aa8 100644 --- a/src/Managers/DeviceManager.cpp +++ b/src/Managers/DeviceManager.cpp @@ -18,8 +18,6 @@ #include "../Utils/String.h" -#define LOG(logLevel, message) LOG_(logLevel, wstring(L"DeviceManager - ") + message) - using namespace std; using namespace lightfx::config; using namespace lightfx::devices; @@ -30,7 +28,7 @@ namespace lightfx { namespace managers { LFXE_API size_t DeviceManager::InitializeDevices() { - LOG(LogLevel::Debug, L"Initializing devices"); + LOG_DEBUG(L"Initializing devices"); size_t i = 0; auto config = this->GetLightFXExtender()->GetConfigManager()->GetMainConfig(); @@ -69,7 +67,7 @@ namespace lightfx { // Load native LightFX devices this->lightFXLibrary = unique_ptr(new LightFX2Proxy(config->AlienwareDllName, config->AlienwareBackupDllName)); if (this->lightFXLibrary->Load()) { - LOG(LogLevel::Debug, L"Alienware LightFX library found"); + LOG_DEBUG(L"Alienware LightFX library found"); LFX_RESULT result; result = this->lightFXLibrary->LFX_Initialize(); @@ -77,7 +75,7 @@ namespace lightfx { unsigned int numDevices = 0; result = this->lightFXLibrary->LFX_GetNumDevices(&numDevices); if (result == LFX_SUCCESS) { - LOG(LogLevel::Debug, to_wstring(numDevices) + L" LightFX devices found"); + LOG_DEBUG(to_wstring(numDevices) + L" LightFX devices found"); for (unsigned int j = 0; j < numDevices; ++j) { auto lightFX = make_shared(); @@ -97,23 +95,23 @@ namespace lightfx { } lightFX->SetDeviceName(deviceName); } else { - LOG(LogLevel::Error, L"Failed to get the device name of LightFX device " + to_wstring(j)); + LOG_ERROR(L"Failed to get the device name of LightFX device " + to_wstring(j)); } LFX_SAFE_DELETE_ARRAY(devDesc); } //TODO: Periodically check for changes (e.g. when a device gets connected or disconnected) } else { - LOG(LogLevel::Error, L"Failed to check the number of LightFX devices: " + this->lightFXLibrary->LfxResultToString(result)); + LOG_ERROR(L"Failed to check the number of LightFX devices: " + this->lightFXLibrary->LfxResultToString(result)); } } else { - LOG(LogLevel::Error, L"Failed to initialize LightFX: " + this->lightFXLibrary->LfxResultToString(result)); + LOG_ERROR(L"Failed to initialize LightFX: " + this->lightFXLibrary->LfxResultToString(result)); } } else { - LOG(LogLevel::Debug, L"Alienware LightFX library not found"); + LOG_DEBUG(L"Alienware LightFX library not found"); } - LOG(LogLevel::Info, L"Successfully initialized " + to_wstring(i) + L" devices"); + LOG_INFO(L"Successfully initialized " + to_wstring(i) + L" devices"); // Enable devices where needed if (config->AutoDeviceDetection) @@ -122,16 +120,16 @@ namespace lightfx { auto device = this->GetChildByIndex(i); if (device == nullptr) { - LOG(LogLevel::Warning, L"Device " + device->GetDeviceName() + L" is configured in settings, but was not found in the system"); + LOG_WARNING(L"Device " + device->GetDeviceName() + L" is configured in settings, but was not found in the system"); continue; } if (!device->IsInitialized()) { - LOG(LogLevel::Warning, L"Device " + device->GetDeviceName() + L" cannot be enabled, because was not initialized"); + LOG_WARNING(L"Device " + device->GetDeviceName() + L" cannot be enabled, because was not initialized"); continue; } bool auto_result = device->Enable(); - LOG(LogLevel::Warning, L"Device " + device->GetDeviceName() + L" was automatically set to " + (auto_result ? L"ON" : L"OFF")); + LOG_WARNING(L"Device " + device->GetDeviceName() + L" was automatically set to " + (auto_result ? L"ON" : L"OFF")); } } else @@ -140,11 +138,11 @@ namespace lightfx { if (device.second) { auto dev = this->GetChild(device.first); if (dev == nullptr) { - LOG(LogLevel::Warning, L"Device " + device.first + L" is configured in settings, but was not found in the system"); + LOG_WARNING(L"Device " + device.first + L" is configured in settings, but was not found in the system"); continue; } if (!dev->IsInitialized()) { - LOG(LogLevel::Warning, L"Device " + device.first + L" cannot be enabled, because was not initialized"); + LOG_WARNING(L"Device " + device.first + L" cannot be enabled, because was not initialized"); continue; } dev->Enable(); @@ -155,7 +153,7 @@ namespace lightfx { } LFXE_API size_t DeviceManager::UninitializeDevices() { - LOG(LogLevel::Debug, L"Uninitializing devices"); + LOG_DEBUG(L"Uninitializing devices"); size_t i = 0; // Unload devices @@ -171,16 +169,16 @@ namespace lightfx { LFX_RESULT result = this->lightFXLibrary->LFX_Release(); if (result == LFX_SUCCESS) { if (this->lightFXLibrary->Unload()) { - LOG(LogLevel::Debug, L"Alienware LightFX library unloaded"); + LOG_DEBUG(L"Alienware LightFX library unloaded"); } else { - LOG(LogLevel::Error, L"Could not unload Alienware LightFX library"); + LOG_ERROR(L"Could not unload Alienware LightFX library"); } } else { - LOG(LogLevel::Error, L"Failed to release LightFX: " + to_wstring(result)); + LOG_ERROR(L"Failed to release LightFX: " + to_wstring(result)); } } - LOG(LogLevel::Info, L"Successfully uninitialized " + to_wstring(i) + L" devices"); + LOG_INFO(L"Successfully uninitialized " + to_wstring(i) + L" devices"); return i; } diff --git a/src/Managers/GameManager.cpp b/src/Managers/GameManager.cpp index d81371f..f33ce53 100644 --- a/src/Managers/GameManager.cpp +++ b/src/Managers/GameManager.cpp @@ -10,8 +10,6 @@ #include "../Utils/Log.h" -#define LOG(logLevel, message) LOG_(logLevel, wstring(L"GameManager - ") + message) - using namespace std; using namespace lightfx::games; using namespace lightfx::utils; @@ -20,19 +18,19 @@ namespace lightfx { namespace managers { bool GameManager::InitializeGame(const std::wstring& fileName) { - LOG(LogLevel::Debug, L"Initializing special game support"); + LOG_DEBUG(L"Initializing special game support"); // Guild Wars 2 auto guildWars2 = make_shared(); if (guildWars2->GetFileName() == fileName) { this->AddChild(guildWars2->GetGameName(), guildWars2); if (guildWars2->Initialize()) { - LOG(LogLevel::Info, L"Guild Wars 2 found"); + LOG_INFO(L"Guild Wars 2 found"); return true; } } - LOG(LogLevel::Info, L"No special game support found"); + LOG_INFO(L"No special game support found"); return false; } @@ -45,7 +43,7 @@ namespace lightfx { } } - LOG(LogLevel::Info, L"Successfully uninitialized " + to_wstring(i) + L" games"); + LOG_INFO(L"Successfully uninitialized " + to_wstring(i) + L" games"); return i; } diff --git a/src/Managers/TrayManager.cpp b/src/Managers/TrayManager.cpp index 724fae0..a8909bb 100644 --- a/src/Managers/TrayManager.cpp +++ b/src/Managers/TrayManager.cpp @@ -33,7 +33,6 @@ #define TRAY_BALLOON_TITLE L"LightFX Extender" #define TRAY_BALLOON_UPDATE_TEXT L" is available.\nClick here to download it." -#define LOG(logLevel, message) LOG_(logLevel, wstring(L"TrayManager - ") + message) using namespace std; using namespace lightfx::config; @@ -64,9 +63,9 @@ namespace lightfx { this->trayIconThread.join(); if (!this->isTrayIconAdded) { - LOG(LogLevel::Debug, L"Tray icon removed"); + LOG_DEBUG(L"Tray icon removed"); } else { - LOG(LogLevel::Debug, L"Failed to remove tray icon"); + LOG_DEBUG(L"Failed to remove tray icon"); } } @@ -121,9 +120,9 @@ namespace lightfx { this->isTrayIconAdded = Shell_NotifyIconW(NIM_ADD, &this->trayIconData) == TRUE; if (this->isTrayIconAdded) { - LOG(LogLevel::Debug, L"Tray icon added"); + LOG_DEBUG(L"Tray icon added"); } else { - LOG(LogLevel::Debug, L"Failed to add tray icon"); + LOG_DEBUG(L"Failed to add tray icon"); } @@ -133,7 +132,7 @@ namespace lightfx { while ((hasMsg = GetMessage(&msg, NULL, 0, 0)) != 0) { if (hasMsg == -1) { // Error - LOG(LogLevel::Error, L"Error in processing tray icon message loop"); + LOG_ERROR(L"Error in processing tray icon message loop"); break; } else { TranslateMessage(&msg); diff --git a/src/Managers/UpdateManager.cpp b/src/Managers/UpdateManager.cpp index 79d0465..3f4574a 100644 --- a/src/Managers/UpdateManager.cpp +++ b/src/Managers/UpdateManager.cpp @@ -28,9 +28,6 @@ #include "../Utils/String.h" #include "../Utils/Windows.h" - -#define LOG(logLevel, message) LOG_(logLevel, wstring(L"UpdateManager - ") + message) - #ifdef _WIN64 #define PLATFORM "x64" #define CORSAIR_DLL_NAME "CUESDK.x64_2013.dll" @@ -39,6 +36,7 @@ #define CORSAIR_DLL_NAME "CUESDK_2013.dll" #endif + using namespace std; using namespace rapidjson; using namespace lightfx::utils; @@ -123,13 +121,13 @@ namespace lightfx { mz_zip_archive archive; memset(&archive, 0, sizeof(archive)); if (!mz_zip_reader_init_mem(&archive, &newVersionZip[0], newVersionZip.size(), 0)) { - LOG(LogLevel::Error, L"Could not open the downloaded archive"); + LOG_ERROR(L"Could not open the downloaded archive"); return false; } mz_zip_archive_file_stat filestat; if (!mz_zip_reader_file_stat(&archive, 0, &filestat)) { - LOG(LogLevel::Error, L"Could not read the downloaded archive"); + LOG_ERROR(L"Could not read the downloaded archive"); mz_zip_reader_end(&archive); return false; } @@ -138,8 +136,8 @@ namespace lightfx { this->InstallNewDll(&archive, "LightFX.dll"); this->InstallNewDll(&archive, CORSAIR_DLL_NAME); } catch (const exception& e) { - LOG(LogLevel::Error, L"Error while installing new DLL: " + string_to_wstring(e.what())); - Log::LogLastWindowsErrorAsync(); + LOG_ERROR(L"Error while installing new DLL: " + string_to_wstring(e.what())); + LOG_WINERROR(); mz_zip_reader_end(&archive); return false; } @@ -177,13 +175,13 @@ namespace lightfx { vector data = {}; HINTERNET hSession = InternetOpenW(L"LightFX Extender Update Manager", 0, NULL, NULL, 0); if (hSession == NULL) { - LOG(LogLevel::Error, L"Failed to open session"); + LOG_ERROR(L"Failed to open session"); return data; } HINTERNET hOpenUrl = InternetOpenUrlW(hSession, url.c_str(), NULL, 0, 1, 1); if (hOpenUrl == NULL) { - LOG(LogLevel::Error, L"Failed to open URL"); + LOG_ERROR(L"Failed to open URL"); InternetCloseHandle(hOpenUrl); return data; } @@ -197,7 +195,7 @@ namespace lightfx { } data.insert(data.end(), buffer, buffer + bytesRead); } else { - LOG(LogLevel::Error, L"Failed to read from URL"); + LOG_ERROR(L"Failed to read from URL"); delete[] buffer; InternetCloseHandle(hOpenUrl); InternetCloseHandle(hSession); @@ -214,31 +212,31 @@ namespace lightfx { LFXE_API void UpdateManager::CheckForUpdate() { Version currentVersion = this->GetCurrentVersion(); - LOG(LogLevel::Debug, L"Checking for updates..."); + LOG_DEBUG(L"Checking for updates..."); auto live = this->GetLiveVersion(); Version liveVersion = live.first; wstring downloadUrl = live.second; if (liveVersion > currentVersion) { wstring newVersionString = liveVersion.ToString(); - LOG(LogLevel::Info, L"A newer version is available: " + newVersionString); + LOG_INFO(L"A newer version is available: " + newVersionString); if (this->GetLightFXExtender()->GetConfigManager()->GetMainConfig()->AutoUpdatesEnabled) { if (this->UpdateLightFX(downloadUrl)) { - LOG(LogLevel::Info, L"LightFX Extender has been updated automatically to " + newVersionString); - LOG(LogLevel::Info, L"The changes will be applied the next time you run LightFX Extender"); - LOG(LogLevel::Info, L"If, for some reason, the newer version will not start, please restore LightFX.dll.bak to LightFX.dll (and disable auto updates in the config and wait for a fix if this keeps on happening)"); + LOG_INFO(L"LightFX Extender has been updated automatically to " + newVersionString); + LOG_INFO(L"The changes will be applied the next time you run LightFX Extender"); + LOG_INFO(L"If, for some reason, the newer version will not start, please restore LightFX.dll.bak to LightFX.dll (and disable auto updates in the config and wait for a fix if this keeps on happening)"); } else { wstring newVersionUrl = this->GetDownloadPageUrl(); - LOG(LogLevel::Warning, L"LightFX Extender could not be updated automatically, see " + newVersionUrl + L" for downloads"); + LOG_INFO(L"LightFX Extender could not be updated automatically, see " + newVersionUrl + L" for downloads"); this->GetLightFXExtender()->GetTrayManager()->SetUpdateNotification(newVersionString, newVersionUrl); } } else { wstring newVersionUrl = this->GetDownloadPageUrl(); - LOG(LogLevel::Info, L"Auto updates are disabled, see " + newVersionUrl + L" for downloads"); + LOG_INFO(L"Auto updates are disabled, see " + newVersionUrl + L" for downloads"); this->GetLightFXExtender()->GetTrayManager()->SetUpdateNotification(newVersionString, newVersionUrl); } } else { - LOG(LogLevel::Debug, L"No update available"); + LOG_INFO(L"No update available"); } } diff --git a/src/Utils/Log.cpp b/src/Utils/Log.cpp index 3437115..cbad02e 100644 --- a/src/Utils/Log.cpp +++ b/src/Utils/Log.cpp @@ -23,6 +23,7 @@ #include "../LightFXExtender.h" #include "FileIO.h" #include "NotifyEvent.h" +#include "String.h" using namespace std; @@ -30,12 +31,6 @@ using namespace std; namespace lightfx { namespace utils { - struct LogMessage { - LogLevel level; - wstring message; - chrono::milliseconds time; - }; - wstring logFileName = L"LightFXExtender.log"; wstring logDirectory = GetDataStorageFolder(); #ifdef LFXE_TESTING @@ -79,7 +74,7 @@ namespace lightfx { //Get the error message, if any. DWORD errorMessageID = GetLastError(); if (errorMessageID == 0) { - LOG_(LogLevel::Debug, L"No Windows error found"); + LOG_DEBUG(L"No Windows error found"); } LPWSTR messageBuffer = nullptr; @@ -94,11 +89,19 @@ namespace lightfx { return L"Windows error: " + message; } - LFXE_API void Log::LogLine(const LogLevel logLevel, const wstring& line) { + LFXE_API void Log::LogLine(const LogLevel logLevel, const string& file, const int line, const string& function, const wstring& message) { if (minimumLogLevel > logLevel) { return; } - wstring logLine = GetLine(logLevel, line, chrono::duration_cast(chrono::system_clock::now().time_since_epoch())); + LogMessage log = { + logLevel, + string_to_wstring(file), + line, + string_to_wstring(function), + message, + chrono::duration_cast(chrono::system_clock::now().time_since_epoch()) + }; + wstring logLine = GetLine(log); try { logMutex.lock(); @@ -111,35 +114,38 @@ namespace lightfx { } } - LFXE_API void Log::LogLastWindowsError() { + LFXE_API void Log::LogLastWindowsError(const string& file, const int line, const string& function) { if (minimumLogLevel > LogLevel::Error) { return; } - LogLine(LogLevel::Error, GetLastWindowsError()); + LogLine(LogLevel::Error, file, line, function, GetLastWindowsError()); } - LFXE_API void Log::LogLineAsync(const LogLevel logLevel, const wstring& line) { + LFXE_API void Log::LogLineAsync(const LogLevel logLevel, const string& file, const int line, const string& function, const wstring& message) { if (minimumLogLevel > logLevel) { return; } - LogMessage message = { + LogMessage log = { logLevel, + string_to_wstring(file), line, + string_to_wstring(function), + message, chrono::duration_cast(chrono::system_clock::now().time_since_epoch()) }; { lock_guard lock(logQueueMutex); - logQueue.emplace(message); + logQueue.emplace(log); } notifyEvent.Notify(); } - LFXE_API void Log::LogLastWindowsErrorAsync() { + LFXE_API void Log::LogLastWindowsErrorAsync(const string& file, const int line, const string& function) { if (minimumLogLevel > LogLevel::Error) { return; } - LogLineAsync(LogLevel::Error, GetLastWindowsError()); + LogLineAsync(LogLevel::Error, file, line, function, GetLastWindowsError()); } @@ -211,20 +217,20 @@ namespace lightfx { return logStream; } - LFXE_API wstring Log::GetLine(const LogLevel logLevel, const wstring& line, chrono::milliseconds logTime) { + LFXE_API wstring Log::GetLine(const LogMessage& message) { // Get a nice date/time prefix first wchar_t buff[20]; - time_t t = chrono::duration_cast(logTime).count(); + time_t t = chrono::duration_cast(message.time).count(); tm lt; localtime_s(<, &t); wcsftime(buff, 20, L"%Y-%m-%d %H:%M:%S", <); wstring timePrefix(buff); - swprintf_s(buff, 4, L"%03ld", logTime.count() % 1000); + swprintf_s(buff, 4, L"%03ld", message.time.count() % 1000); timePrefix += L"." + wstring(buff); // Determine the log level prefix wstring logLevelPrefix; - switch (logLevel) { + switch (message.level) { case LogLevel::Debug: logLevelPrefix = L"[DEBUG]"; break; @@ -239,7 +245,7 @@ namespace lightfx { break; } - return timePrefix + L" - " + logLevelPrefix + L" " + line; + return timePrefix + L" - " + logLevelPrefix + L" " + message.file + L":" + to_wstring(message.line) + L" (" + message.function + L") - " + message.message; } LFXE_API void Log::WriteBacklog() { @@ -259,7 +265,7 @@ namespace lightfx { } } - wstring logLine = GetLine(message.level, message.message, message.time); + wstring logLine = GetLine(message); logStream << logLine << endl; } diff --git a/src/Utils/Log.h b/src/Utils/Log.h index 65b06c7..f7713a1 100644 --- a/src/Utils/Log.h +++ b/src/Utils/Log.h @@ -8,9 +8,15 @@ #include "../Common/ApiExports.h" -#define LOG_(logLevel, message) { \ +#define LOG(logLevel, message) { \ if (::lightfx::utils::Log::GetMinimumLogLevel() <= logLevel) { \ - ::lightfx::utils::Log::LogLineAsync(logLevel, message); } } + ::lightfx::utils::Log::LogLineAsync(logLevel, __FILE__, __LINE__, __FUNCTION__, message); } } + +#define LOG_DEBUG(message) LOG(::lightfx::utils::LogLevel::Debug, message) +#define LOG_INFO(message) LOG(::lightfx::utils::LogLevel::Info, message) +#define LOG_WARNING(message) LOG(::lightfx::utils::LogLevel::Warning, message) +#define LOG_ERROR(message) LOG(::lightfx::utils::LogLevel::Error, message) +#define LOG_WINERROR() ::lightfx::utils::Log::LogLastWindowsErrorAsync(__FILE__, __LINE__, __FUNCTION__) #pragma warning(push) #pragma warning(disable : 4251) @@ -26,16 +32,25 @@ namespace lightfx { Off = 99 }; + struct LFXE_API LogMessage { + LogLevel level; + std::wstring file; + int line; + std::wstring function; + std::wstring message; + std::chrono::milliseconds time; + }; + class LFXE_API Log { public: static void StartLoggerWorker(); static void StopLoggerWorker(); - static void LogLine(const LogLevel logLevel, const std::wstring& line); - static void LogLastWindowsError(); - static void LogLineAsync(const LogLevel logLevel, const std::wstring& line); - static void LogLastWindowsErrorAsync(); + static void LogLine(const LogLevel logLevel, const std::string& file, const int line, const std::string& function, const std::wstring& message); + static void LogLastWindowsError(const std::string& file, const int line, const std::string& function); + static void LogLineAsync(const LogLevel logLevel, const std::string& file, const int line, const std::string& function, const std::wstring& message); + static void LogLastWindowsErrorAsync(const std::string& file, const int line, const std::string& function); static void RotateLog(); @@ -50,7 +65,7 @@ namespace lightfx { static void LoggerWorker(); static std::wofstream OpenStream(); - static std::wstring GetLine(const LogLevel logLevel, const std::wstring& line, std::chrono::milliseconds logTime); + static std::wstring GetLine(const LogMessage& message); static void WriteBacklog(); }; diff --git a/tests/Utils/LogTest.cpp b/tests/Utils/LogTest.cpp index c4cae88..2b601c9 100644 --- a/tests/Utils/LogTest.cpp +++ b/tests/Utils/LogTest.cpp @@ -40,7 +40,7 @@ namespace lightfx_tests { Log::SetLogDirectory(L"./"); Log::SetMinimumLogLevel(LogLevel::Debug); - Log::LogLine(LogLevel::Info, L"Test log line"); + Log::LogLine(LogLevel::Info, __FILE__, __LINE__, __FUNCTION__, L"Test log line"); BOOL exists = PathFileExistsW(Log::GetLogFileName().c_str()); DeleteFileW(Log::GetLogFileName().c_str()); @@ -52,7 +52,7 @@ namespace lightfx_tests { Log::SetLogDirectory(L"./"); Log::SetMinimumLogLevel(LogLevel::Debug); - Log::LogLastWindowsError(); + Log::LogLastWindowsError(__FILE__, __LINE__, __FUNCTION__); BOOL exists = PathFileExistsW(Log::GetLogFileName().c_str()); DeleteFileW(Log::GetLogFileName().c_str());