Skip to content
This repository has been archived by the owner on May 30, 2018. It is now read-only.

Commit

Permalink
Improve logging by including filename, line number and function
Browse files Browse the repository at this point in the history
  • Loading branch information
Archomeda committed Jan 1, 2016
1 parent fa1b61a commit 55299e1
Show file tree
Hide file tree
Showing 24 changed files with 167 additions and 187 deletions.
12 changes: 5 additions & 7 deletions src/Config/ConfigFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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()));
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/Config/MainConfigFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#define CONF_GAMES_GUILDWARS2_TEAMCOLORANIMATION L"TeamColorAnimation"
#pragma endregion


using namespace std;
using namespace rapidjson;
using namespace lightfx::managers;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions src/Config/MainConfigFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 6 additions & 8 deletions src/Devices/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,15 +38,15 @@ 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;
}

LFXE_API bool Device::Disable() {
if (this->isEnabled) {
LOG(LogLevel::Debug, L"Disabling");
LOG_DEBUG(L"Disabling " + this->GetDeviceName());
this->isEnabled = false;
}
return true;
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -92,7 +90,7 @@ namespace lightfx {
unsigned long timelineTick = (timeTick - this->timelineStart).count();
vector<LightColor> 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();
Expand Down
8 changes: 3 additions & 5 deletions src/Devices/DeviceCorsair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +31,7 @@ namespace lightfx {
// Load the library first
this->library = unique_ptr<CUESDKProxy>(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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<unsigned int>(vec.size()), vec.data(), nullptr, nullptr);
}
Expand Down
24 changes: 11 additions & 13 deletions src/Devices/DeviceLightFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +31,7 @@ namespace lightfx {
auto config = this->GetManager()->GetLightFXExtender()->GetConfigManager()->GetMainConfig();
this->library = unique_ptr<LightFX2Proxy>(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;
}
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -76,24 +74,24 @@ 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;
result = this->library->LFX_GetLightLocation(this->GetDeviceIndex(), i, &lightLoc);
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);
}
Expand Down Expand Up @@ -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;
}
Expand Down
24 changes: 11 additions & 13 deletions src/Devices/DeviceLightpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
Expand All @@ -157,7 +155,7 @@ namespace lightfx {
}

bool DeviceLightpack::DisconnectAPI() {
LOG(LogLevel::Debug, L"DisconnectAPI()");
LOG_DEBUG(L"Disconnecting from API");

this->Unlock();

Expand All @@ -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<int>::max()) {
Expand Down Expand Up @@ -203,7 +201,7 @@ namespace lightfx {
// Error
}

LOG(LogLevel::Debug, L"ReceiveAPI(): " + wresult);
LOG_DEBUG(L"Receive: " + wresult);
return wresult;
}

Expand Down Expand Up @@ -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;

/*
Expand Down
6 changes: 2 additions & 4 deletions src/Devices/DeviceLogitech.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit 55299e1

Please sign in to comment.