diff --git a/Controllers/AsusAuraSMBusController/AsusAuraSMBusControllerDetect.cpp b/Controllers/AsusAuraSMBusController/AsusAuraSMBusControllerDetect.cpp index 8f76f9a5..98e89bb1 100644 --- a/Controllers/AsusAuraSMBusController/AsusAuraSMBusControllerDetect.cpp +++ b/Controllers/AsusAuraSMBusController/AsusAuraSMBusControllerDetect.cpp @@ -89,7 +89,7 @@ bool TestForAsusAuraSMBusController(i2c_smbus_interface* bus, unsigned char addr { bool pass = false; - LOG_DEBUG("Testing address %02X for Aura SMBus controller", address); + LOG_DEBUG("[Aura SMBus] looking for devices at 0x%02X...", address); int res = bus->i2c_smbus_write_quick(address, I2C_SMBUS_WRITE); @@ -97,7 +97,7 @@ bool TestForAsusAuraSMBusController(i2c_smbus_interface* bus, unsigned char addr { pass = true; - LOG_DEBUG("Detected an I2C device at address %02X, testing register range for Aura SMBus", address); + LOG_DEBUG("[Aura SMBus] Detected an I2C device at address %02X, testing register range", address); for (int i = 0xA0; i < 0xB0; i++) { @@ -105,7 +105,7 @@ bool TestForAsusAuraSMBusController(i2c_smbus_interface* bus, unsigned char addr if (res != (i - 0xA0)) { - LOG_DEBUG("Detection failed testing register %02X. Expected %02X, got %02X.", i, (i - 0xA0), res); + LOG_VERBOSE("[Aura SMBus] Detection failed testing register %02X. Expected %02X, got %02X.", i, (i - 0xA0), res); pass = false; } @@ -113,7 +113,7 @@ bool TestForAsusAuraSMBusController(i2c_smbus_interface* bus, unsigned char addr if(pass) { - LOG_DEBUG("Detection successful, address %02X appears to be an Aura SMBus controller", address); + LOG_VERBOSE("[Aura SMBus] Detection successful, address %02X", address); } } @@ -143,7 +143,7 @@ void DetectAsusAuraSMBusDRAMControllers(std::vector &busse IF_DRAM_SMBUS(busses[bus]->pci_vendor, busses[bus]->pci_device) { - LOG_DEBUG("Remapping Aura SMBus RAM modules on 0x77"); + LOG_DEBUG("[ASUS Aura SMBus DRAM] Remapping Aura SMBus RAM modules on 0x77"); for (unsigned int slot = 0; slot < 8; slot++) { @@ -151,7 +151,7 @@ void DetectAsusAuraSMBusDRAMControllers(std::vector &busse if (res < 0) { - LOG_DEBUG("No device detected at address 0x77, aborting remap"); + LOG_DEBUG("[ASUS Aura SMBus DRAM] No device detected at 0x77, aborting remap"); break; } @@ -162,7 +162,7 @@ void DetectAsusAuraSMBusDRAMControllers(std::vector &busse if(address_list_idx < AURA_RAM_ADDRESS_COUNT) { - LOG_DEBUG("Testing address %02X to see if there is a device there", aura_ram_addresses[address_list_idx]); + LOG_DEBUG("[ASUS Aura SMBus DRAM] Testing address %02X to see if there is a device there", aura_ram_addresses[address_list_idx]); res = busses[bus]->i2c_smbus_write_quick(aura_ram_addresses[address_list_idx], I2C_SMBUS_WRITE); } @@ -174,7 +174,7 @@ void DetectAsusAuraSMBusDRAMControllers(std::vector &busse if(address_list_idx < AURA_RAM_ADDRESS_COUNT) { - LOG_DEBUG("Remapping slot %d to address %02X", slot, aura_ram_addresses[address_list_idx]); + LOG_DEBUG("[ASUS Aura SMBus DRAM] Remapping slot %d to address %02X", slot, aura_ram_addresses[address_list_idx]); AsusAuraRegisterWrite(busses[bus], 0x77, AURA_REG_SLOT_INDEX, slot); AsusAuraRegisterWrite(busses[bus], 0x77, AURA_REG_I2C_ADDRESS, (aura_ram_addresses[address_list_idx] << 1)); diff --git a/Controllers/LogitechController/LogitechControllerDetect.cpp b/Controllers/LogitechController/LogitechControllerDetect.cpp index cff25d0c..4f2e1837 100644 --- a/Controllers/LogitechController/LogitechControllerDetect.cpp +++ b/Controllers/LogitechController/LogitechControllerDetect.cpp @@ -349,7 +349,7 @@ static void addLogitechLightsyncMouse1zone(hid_device_info* info, const std::str } else { - LOG_NOTICE("Unable to open all device report endpoints, unable to add device"); + LOG_INFO("Unable to open all device report endpoints, unable to add device"); hid_close(dev_usage_1); hid_close(dev_usage_2); } @@ -409,7 +409,7 @@ static void addLogitechLightsyncMouse2zone(hid_device_info* info, const std::str } else { - LOG_NOTICE("Unable to open all device report endpoints, unable to add device"); + LOG_INFO("Unable to open all device report endpoints, unable to add device"); hid_close(dev_usage_1); hid_close(dev_usage_2); } diff --git a/Controllers/LogitechController/LogitechProtocolCommon.cpp b/Controllers/LogitechController/LogitechProtocolCommon.cpp index 26403049..8a59f4f1 100644 --- a/Controllers/LogitechController/LogitechProtocolCommon.cpp +++ b/Controllers/LogitechController/LogitechProtocolCommon.cpp @@ -22,7 +22,7 @@ int getWirelessDevice(usages device_usages, uint16_t pid, wireless_map *wireless usages::iterator find_usage = device_usages.find(1); if (find_usage == device_usages.end()) { - LOG_NOTICE("Unable get_Wireless_Device due to missing FAP Short Message (0x10) usage"); + LOG_INFO("Unable get_Wireless_Device due to missing FAP Short Message (0x10) usage"); LOG_DEBUG("Dumping device usages:"); for(usages::iterator dev = device_usages.begin(); dev != device_usages.end(); dev++) { @@ -66,11 +66,11 @@ int getWirelessDevice(usages device_usages, uint16_t pid, wireless_map *wireless result = hid_read_timeout(dev_use1, response.buffer, response.size(), LOGITECH_PROTOCOL_TIMEOUT); unsigned int device_count = response.data[1]; - LOG_NOTICE("Count of connected devices to %4X: %i", pid, device_count); + LOG_INFO("Count of connected devices to %4X: %i", pid, device_count); if (device_count > 0) { - LOG_NOTICE("Faking a reconnect to get device list"); + LOG_INFO("Faking a reconnect to get device list"); device_count++; //Add 1 to the device_count to include the receiver response.init(); @@ -87,7 +87,7 @@ int getWirelessDevice(usages device_usages, uint16_t pid, wireless_map *wireless hid_read_timeout(dev_use1, devices.buffer, devices.size(), LOGITECH_PROTOCOL_TIMEOUT); unsigned int wireless_PID = (devices.data[2] << 8) | devices.data[1]; - LOG_NOTICE("Connected Device Index %i:\tVirtualID=%04X\t\t%02X %02X %02X %02X %02X %02X %02X", i, wireless_PID, devices.buffer[0], devices.buffer[1], devices.buffer[2], devices.buffer[3], devices.buffer[4], devices.buffer[5], devices.buffer[6]); + LOG_INFO("Connected Device Index %i:\tVirtualID=%04X\t\t%02X %02X %02X %02X %02X %02X %02X", i, wireless_PID, devices.buffer[0], devices.buffer[1], devices.buffer[2], devices.buffer[3], devices.buffer[4], devices.buffer[5], devices.buffer[6]); /*-----------------------------------------------------------------*\ | We need to read the receiver from the HID device queue but | @@ -164,10 +164,10 @@ void logitech_device::initialiseDevice() | dump the entire Feature list to log | \*-----------------------------------------------------------------*/ getDeviceFeatureList(); //This will populate the feature list - LOG_NOTICE("Unable add this device due to missing RGB Effects Feature"); + LOG_INFO("Unable add this device due to missing RGB Effects Feature"); for(features::iterator feature = feature_list.begin(); feature != feature_list.end(); feature++) { - LOG_NOTICE("Feature Index: %02X\tFeature Page: %04X", feature->second, feature->first); + LOG_INFO("Feature Index: %02X\tFeature Page: %04X", feature->second, feature->first); } } else @@ -238,7 +238,7 @@ hid_device* logitech_device::getDevice(uint8_t usage_index) if (find_usage == device_usages.end()) { - LOG_NOTICE("Unable add this device due to missing FAP Message usage %i", usage_index); + LOG_INFO("Unable add this device due to missing FAP Message usage %i", usage_index); return nullptr; } else @@ -333,11 +333,11 @@ int logitech_device::getDeviceFeatureList() { if(!dev_use1) { - LOG_NOTICE("Unable add this device due to missing FAP Short Message (0x10) usage"); + LOG_INFO("Unable add this device due to missing FAP Short Message (0x10) usage"); } if(!dev_use2) { - LOG_NOTICE("Unable add this device due to missing FAP Long Message (0x11) usage"); + LOG_INFO("Unable add this device due to missing FAP Long Message (0x11) usage"); } } diff --git a/Controllers/LogitechController/RGBController_LogitechLightspeed.cpp b/Controllers/LogitechController/RGBController_LogitechLightspeed.cpp index 84f67a50..a7a1a006 100644 --- a/Controllers/LogitechController/RGBController_LogitechLightspeed.cpp +++ b/Controllers/LogitechController/RGBController_LogitechLightspeed.cpp @@ -41,7 +41,7 @@ RGBController_LogitechLightspeed::RGBController_LogitechLightspeed(LogitechLight default: type = DEVICE_TYPE_UNKNOWN; - LOG_NOTICE("Logitech device type not known: %i", logitech->lightspeed->logitech_device_type); + LOG_INFO("Logitech device type not known: %i", logitech->lightspeed->logitech_device_type); } mode Direct; diff --git a/Controllers/OpenRazerController/OpenRazerDetect.cpp b/Controllers/OpenRazerController/OpenRazerDetect.cpp index 84b80f1e..f745d9e3 100644 --- a/Controllers/OpenRazerController/OpenRazerDetect.cpp +++ b/Controllers/OpenRazerController/OpenRazerDetect.cpp @@ -1,4 +1,5 @@ #include "Detector.h" +#include "LogManager.h" #include "RGBController.h" #include "RGBController_OpenRazer.h" #include @@ -67,6 +68,8 @@ void DetectOpenRazerControllers(std::vector &rgb_controllers) dir = opendir(driver_path); + LOG_DEBUG("[OpenRazer] Folder %s is %s", driver_path, (dir == NULL)?"not found":"found look for driver..." ); + if(dir == NULL) { driver_to_read++; @@ -107,6 +110,7 @@ void DetectOpenRazerControllers(std::vector &rgb_controllers) } else { + LOG_DEBUG("[OpenRazer] Device index is not -1 delete controller"); delete razer_rgb; } diff --git a/Controllers/OpenRazerController/OpenRazerWindowsDetect.cpp b/Controllers/OpenRazerController/OpenRazerWindowsDetect.cpp index a0851ce1..cb504c73 100644 --- a/Controllers/OpenRazerController/OpenRazerWindowsDetect.cpp +++ b/Controllers/OpenRazerController/OpenRazerWindowsDetect.cpp @@ -1,4 +1,5 @@ #include "Detector.h" +#include "LogManager.h" #include "RGBController.h" #include "RGBController_OpenRazerWindows.h" #include @@ -113,7 +114,9 @@ void DetectOpenRazerControllers(std::vector &rgb_controllers) { static HMODULE module = LoadLibrary(OPENRAZERDLL); - if(module == nullptr) + LOG_DEBUG("[OpenRazerWindows] The %s is %s", OPENRAZERDLL, (module == nullptr)?"not found":"found" ); + + if(module == nullptr) { return; } @@ -179,6 +182,7 @@ void DetectOpenRazerControllers(std::vector &rgb_controllers) } else { + LOG_DEBUG("[OpenRazerWindows] Device index is not -1 delete controller"); delete razer_rgb; } } @@ -203,6 +207,7 @@ void DetectOpenRazerControllers(std::vector &rgb_controllers) } else { + LOG_DEBUG("[OpenRazerWindows] Device index is not -1 delete controller"); delete razer_rgb; } } @@ -227,6 +232,7 @@ void DetectOpenRazerControllers(std::vector &rgb_controllers) } else { + LOG_DEBUG("[OpenRazerWindows] Device index is not -1 delete controller"); delete razer_rgb; } } @@ -251,6 +257,7 @@ void DetectOpenRazerControllers(std::vector &rgb_controllers) } else { + LOG_DEBUG("[OpenRazerWindows] Device index is not -1 delete controller"); delete razer_rgb; } } @@ -275,6 +282,7 @@ void DetectOpenRazerControllers(std::vector &rgb_controllers) } else { + LOG_DEBUG("[OpenRazerWindows] Device index is not -1 delete controller"); delete razer_rgb; } } diff --git a/Controllers/PhilipsHueController/PhilipsHueControllerDetect.cpp b/Controllers/PhilipsHueController/PhilipsHueControllerDetect.cpp index ca31ec9d..12b951d2 100644 --- a/Controllers/PhilipsHueController/PhilipsHueControllerDetect.cpp +++ b/Controllers/PhilipsHueController/PhilipsHueControllerDetect.cpp @@ -224,7 +224,7 @@ void DetectPhilipsHueControllers(std::vector& rgb_controllers) } catch(std::exception &e) { - LOG_NOTICE("Exception occurred in Philips Hue detection"); + LOG_INFO("Exception occurred in Philips Hue detection"); } } } /* DetectPhilipsHueControllers() */ diff --git a/Controllers/RazerController/RazerControllerDetect.cpp b/Controllers/RazerController/RazerControllerDetect.cpp index f59d3dfc..fcc887b1 100644 --- a/Controllers/RazerController/RazerControllerDetect.cpp +++ b/Controllers/RazerController/RazerControllerDetect.cpp @@ -1,4 +1,5 @@ #include "Detector.h" +#include "LogManager.h" #include "RazerController.h" #include "RazerKrakenController.h" #include "RazerDevices.h" @@ -66,6 +67,7 @@ void DetectRazerControllers(hid_device_info* info, const std::string& name) if(openrazer_enabled) { + LOG_VERBOSE("[DetectRazer] OpenRazer controller is enabled stop this detection"); return; } @@ -183,6 +185,7 @@ void DetectRazerKrakenControllers(hid_device_info* info, const std::string& name if(openrazer_enabled) { + LOG_VERBOSE("[DetectRazerKraken] OpenRazer controller is enabled stop this detection"); return; } diff --git a/LogManager.cpp b/LogManager.cpp index 6ec1fc44..a1ec5c39 100644 --- a/LogManager.cpp +++ b/LogManager.cpp @@ -2,14 +2,18 @@ #include #include +#include +#include + #include "ResourceManager.h" #include "filesystem.h" -static const char* log_codes[] = {"CRITICAL", "ERROR", "Message", "Warning", "Notice", "[verbose]", "Debug"}; +static const char* log_codes[] = {"FATAL:", "ERROR:", "Warning:", "Info:", "[verbose]", "Debug:", "Trace:"}; LogManager::LogManager() { + base_clock = clock(); } LogManager* LogManager::get() @@ -132,7 +136,9 @@ void LogManager::_flush() if(temp_messages[msg]->level <= loglevel) { // Put the timestamp here - log_stream << log_codes[temp_messages[msg]->level] << ": "; + clock_t counter = temp_messages[msg]->counted_second; + log_stream << std::left << std::setw(6) << counter/ ( CLOCKS_PER_SEC / 1000 ) << "|"; + log_stream << std::left << std::setw(9) << log_codes[temp_messages[msg]->level]; log_stream << temp_messages[msg]->buffer; if(print_source) @@ -168,7 +174,7 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con | If a critical message occurs, enable source | | printing and set loglevel and verbosity to highest| \*-------------------------------------------------*/ - if(level == LL_CRITICAL) + if(level == LL_FATAL) { print_source = true; loglevel = LL_DEBUG; @@ -193,9 +199,10 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con /*-------------------------------------------------*\ | Fill in message information | \*-------------------------------------------------*/ - mes->level = level; - mes->filename = filename; - mes->line = line; + mes->level = level; + mes->filename = filename; + mes->line = line; + mes->counted_second = clock() - base_clock; /*-------------------------------------------------*\ | If the message is within the current verbosity, | @@ -212,18 +219,6 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con std::cout << std::endl; } - /*-------------------------------------------------*\ - | If the message level is LL_MESSAGE or lower, add | - | it to the error queue | - \*-------------------------------------------------*/ - if(level <= LL_MESSAGE) - { - for(size_t idx = 0; idx < error_callbacks.size(); ++idx) - { - error_callbacks[idx].first(error_callbacks[idx].second, mes); - } - } - /*-------------------------------------------------*\ | Add the message to the logfile queue | \*-------------------------------------------------*/ @@ -233,6 +228,18 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con | Flush the queues | \*-------------------------------------------------*/ _flush(); + + /*-------------------------------------------------*\ + | If the message level is LL_WARNING or lower, add | + | it to the error queue | + \*-------------------------------------------------*/ + if(level <= LL_WARNING) + { + for(size_t idx = 0; idx < error_callbacks.size(); ++idx) + { + error_callbacks[idx].first(error_callbacks[idx].second, mes); + } + } } void LogManager::append(const char* filename, int line, unsigned int level, const char* fmt, ...) @@ -252,14 +259,9 @@ void LogManager::setLoglevel(unsigned int level) | Check that the new log level is valid, otherwise | | set it within the valid range | \*-------------------------------------------------*/ - if(level < LL_CRITICAL) + if(level > LL_TRACE) { - level = LL_CRITICAL; - } - - if(level > LL_DEBUG) - { - level = LL_DEBUG; + level = LL_TRACE; } LOG_DEBUG("Loglevel set to %d", level); @@ -276,14 +278,10 @@ void LogManager::setVerbosity(unsigned int level) | Check that the new verbosity is valid, otherwise | | set it within the valid range | \*-------------------------------------------------*/ - if(level < LL_CRITICAL) - { - level = LL_CRITICAL; - } - if(level > LL_DEBUG) + if(level > LL_TRACE) { - level = LL_DEBUG; + level = LL_TRACE; } LOG_DEBUG("Verbosity set to %d", level); diff --git a/LogManager.h b/LogManager.h index 11697377..55d73d79 100644 --- a/LogManager.h +++ b/LogManager.h @@ -12,13 +12,13 @@ using json = nlohmann::json; enum { - LL_CRITICAL, // Critical unrecoverable errors that cause a generalized crash of a module or of the entire app + LL_FATAL, // Critical unrecoverable errors that cause a generalized crash of a module or of the entire app LL_ERROR, // Local errors that abort an operation - LL_MESSAGE, // Things the user should be informed of, not necessarily errors LL_WARNING, // Local errors that may cause an operation to have an undefined behavior or may have dangerous/unforeseen consequences - LL_NOTICE, // Initialization messages, significant actions and follow-up information + LL_INFO, // Initialization messages, significant actions and follow-up information LL_VERBOSE, // Tracing of commands and performed actions, usually for debug purposes, comments on the higher priority messages LL_DEBUG, // Deep tracing, "printf-style debugging" alternative, for debug purposes. Such messages should be put all over the code instead of comments + LL_TRACE }; struct LogMessage @@ -27,6 +27,7 @@ struct LogMessage unsigned int level; const char* filename; int line; + clock_t counted_second; // int timestamp or float time_offset? TBD }; typedef std::shared_ptr PLogMessage; @@ -53,11 +54,14 @@ private: bool print_source = false; // Logfile max level - unsigned int loglevel = LL_NOTICE; + unsigned int loglevel = LL_INFO; // Verbosity (stdout) max level unsigned int verbosity = LL_WARNING; + //Clock from LogManager creation + clock_t base_clock; + // A non-guarded append() void _append(const char* filename, int line, unsigned int level, const char* fmt, va_list va); @@ -79,12 +83,12 @@ public: }; #define LogAppend(level, ...) LogManager::get()->append(__FILE__, __LINE__, level, __VA_ARGS__) -#define LOG_CRITICAL(...) LogAppend(LL_CRITICAL, __VA_ARGS__) +#define LOG_FATAL(...) LogAppend(LL_FATAL, __VA_ARGS__) #define LOG_ERROR(...) LogAppend(LL_ERROR, __VA_ARGS__) -#define LOG_MESSAGE(...) LogAppend(LL_MESSAGE, __VA_ARGS__) #define LOG_WARNING(...) LogAppend(LL_WARNING, __VA_ARGS__) -#define LOG_NOTICE(...) LogAppend(LL_NOTICE, __VA_ARGS__) +#define LOG_INFO(...) LogAppend(LL_INFO, __VA_ARGS__) #define LOG_VERBOSE(...) LogAppend(LL_VERBOSE, __VA_ARGS__) #define LOG_DEBUG(...) LogAppend(LL_DEBUG, __VA_ARGS__) +#define LOG_TRACE(...) LogAppend(LL_TRACE, __VA_ARGS__) #endif // LOGMANAGER_H diff --git a/NetworkServer.cpp b/NetworkServer.cpp index d65e5812..cf4972c8 100644 --- a/NetworkServer.cpp +++ b/NetworkServer.cpp @@ -43,7 +43,7 @@ NetworkClientInfo::~NetworkClientInfo() { if(client_sock != INVALID_SOCKET) { - LOG_NOTICE("Closing server connection: %s", client_ip); + LOG_INFO("Closing server connection: %s", client_ip); delete client_listen_thread; shutdown(client_sock, SD_RECEIVE); closesocket(client_sock); diff --git a/PluginManager.cpp b/PluginManager.cpp index b424b8ba..46e41163 100644 --- a/PluginManager.cpp +++ b/PluginManager.cpp @@ -3,7 +3,7 @@ void PluginManager::ScanAndLoadPlugins(bool dark_theme) { - LOG_NOTICE("Loading plugins"); + LOG_INFO("Loading plugins"); std::string OpenRGBConfigDir = ResourceManager::get()->GetConfigurationDirectory(); diff --git a/ProfileManager.cpp b/ProfileManager.cpp index f2a0c766..28193320 100644 --- a/ProfileManager.cpp +++ b/ProfileManager.cpp @@ -359,7 +359,7 @@ bool ProfileManager::LoadProfileWithOptions { ret_val = LoadDeviceFromListWithOptions(temp_controllers, temp_controller_used, controllers[controller_index], load_size, load_settings); std::string current_name = controllers[controller_index]->name + " @ " + controllers[controller_index]->location; - LOG_NOTICE("Profile loading: %s for %s", ( ret_val ? "Succeeded" : "FAILED!" ), current_name.c_str()); + LOG_INFO("Profile loading: %s for %s", ( ret_val ? "Succeeded" : "FAILED!" ), current_name.c_str()); } /*---------------------------------------------------------*\ @@ -393,7 +393,7 @@ void ProfileManager::UpdateProfileList() if(filename.find(".orp") != std::string::npos) { - LOG_NOTICE("Found file: %s attempting to validate header", filename.c_str()); + LOG_INFO("Found file: %s attempting to validate header", filename.c_str()); /*---------------------------------------------------------*\ | Open input file in binary mode | @@ -419,7 +419,7 @@ void ProfileManager::UpdateProfileList() filename.erase(filename.length() - 4); profile_list.push_back(filename); - LOG_NOTICE("Valid v%i profile found for %s", profile_version, filename.c_str()); + LOG_INFO("Valid v%i profile found for %s", profile_version, filename.c_str()); } } diff --git a/ResourceManager.cpp b/ResourceManager.cpp index c65fad0f..2b4a1023 100644 --- a/ResourceManager.cpp +++ b/ResourceManager.cpp @@ -94,7 +94,7 @@ ResourceManager::~ResourceManager() void ResourceManager::RegisterI2CBus(i2c_smbus_interface *bus) { - LOG_NOTICE("Registering I2C interface: %s", bus->device_name); + LOG_INFO("Registering I2C interface: %s", bus->device_name); busses.push_back(bus); } @@ -105,7 +105,7 @@ std::vector & ResourceManager::GetI2CBusses() void ResourceManager::RegisterRGBController(RGBController *rgb_controller) { - LOG_NOTICE("Registering RGB controller: %s", rgb_controller->name.c_str()); + LOG_INFO("Registering RGB controller: %s", rgb_controller->name.c_str()); rgb_controllers_hw.push_back(rgb_controller); UpdateDeviceList(); @@ -113,7 +113,7 @@ void ResourceManager::RegisterRGBController(RGBController *rgb_controller) void ResourceManager::UnregisterRGBController(RGBController* rgb_controller) { - LOG_NOTICE("Unregistering RGB controller: %s", rgb_controller->name.c_str()); + LOG_INFO("Unregistering RGB controller: %s", rgb_controller->name.c_str()); /*-------------------------------------------------------------------------*\ | Clear callbacks from the controller before removal | @@ -601,6 +601,44 @@ void ResourceManager::DisableDetection() detection_enabled = false; } +const char* wchar_to_char(const wchar_t* pwchar) +{ + if (pwchar == nullptr) + { + return ""; + } + // get the number of characters in the string. + int currentCharIndex = 0; + char currentChar = pwchar[currentCharIndex]; + + while (currentChar != '\0') + { + currentCharIndex++; + currentChar = pwchar[currentCharIndex]; + } + + const int charCount = currentCharIndex + 1; + + // allocate a new block of memory size char (1 byte) instead of wide char (2 bytes) + char* filePathC = (char*)malloc(sizeof(char) * charCount); + + for (int i = 0; i < charCount; i++) + { + // convert to char (1 byte) + char character = pwchar[i]; + + *filePathC = character; + + filePathC += sizeof(char); + + } + filePathC += '\0'; + + filePathC -= (sizeof(char) * charCount); + + return filePathC; +} + void ResourceManager::DetectDevicesThreadFunction() { DetectDeviceMutex.lock(); @@ -615,7 +653,9 @@ void ResourceManager::DetectDevicesThreadFunction() unsigned int prev_count = 0; std::vector size_used; - LOG_NOTICE("Detection started"); + LOG_INFO("------------------------------------------------------"); + LOG_INFO("| Start device detection |"); + LOG_INFO("------------------------------------------------------"); size_used.resize(rgb_controllers_sizes.size()); @@ -635,7 +675,7 @@ void ResourceManager::DetectDevicesThreadFunction() \*-------------------------------------------------*/ int hid_status = hid_init(); - LOG_NOTICE("Initializing HID interfaces: %s", ((hid_status == 0) ? "Success" : "Failed")); + LOG_INFO("Initializing HID interfaces: %s", ((hid_status == 0) ? "Success" : "Failed")); /*-------------------------------------------------*\ | Check HID safe mode setting | @@ -677,8 +717,10 @@ void ResourceManager::DetectDevicesThreadFunction() /*-------------------------------------------------*\ | Detect i2c interfaces | \*-------------------------------------------------*/ - LOG_NOTICE("Detecting I2C interfaces"); - + LOG_INFO("------------------------------------------------------"); + LOG_INFO("| Detecting I2C interfaces |"); + LOG_INFO("------------------------------------------------------"); + for(unsigned int i2c_bus_detector_idx = 0; i2c_bus_detector_idx < i2c_bus_detectors.size() && detection_is_required.load(); i2c_bus_detector_idx++) { i2c_bus_detectors[i2c_bus_detector_idx](); @@ -688,8 +730,9 @@ void ResourceManager::DetectDevicesThreadFunction() /*-------------------------------------------------*\ | Detect i2c devices | \*-------------------------------------------------*/ - LOG_NOTICE("Detecting I2C devices"); - + LOG_INFO("------------------------------------------------------"); + LOG_INFO("| Detecting I2C devices |"); + LOG_INFO("------------------------------------------------------"); for(unsigned int i2c_detector_idx = 0; i2c_detector_idx < i2c_device_detectors.size() && detection_is_required.load(); i2c_detector_idx++) { detection_string = i2c_device_detector_strings[i2c_detector_idx].c_str(); @@ -703,6 +746,7 @@ void ResourceManager::DetectDevicesThreadFunction() this_device_enabled = detector_settings["detectors"][detection_string]; } + LOG_DEBUG("[%s] is %s", detection_string, ((this_device_enabled == true) ? "Enabled" : "Disabled")); if(this_device_enabled) { DetectionProgressChanged(); @@ -726,8 +770,14 @@ void ResourceManager::DetectDevicesThreadFunction() UpdateDeviceList(); } + else + { + LOG_DEBUG("[%s] no devices found", detection_string); + } prev_count = rgb_controllers_hw.size(); + LOG_TRACE("[%s] detection end", detection_string); + /*-------------------------------------------------*\ | Update detection percent | \*-------------------------------------------------*/ @@ -736,17 +786,21 @@ void ResourceManager::DetectDevicesThreadFunction() detection_percent = percent * 100.0f; } + /*-------------------------------------------------*\ | Detect HID devices | | | | Reset current device pointer to first device | \*-------------------------------------------------*/ + LOG_INFO("------------------------------------------------------"); + LOG_INFO("| Detecting HID devices |"); + if (hid_safe_mode) + LOG_INFO("| with safe mode |"); + LOG_INFO("------------------------------------------------------"); current_hid_device = hid_devices; if(hid_safe_mode) { - LOG_NOTICE("Detecting HID devices in safe mode"); - /*-----------------------------------------------------------------------------*\ | Loop through all available detectors. If all required information matches, | | run the detector | @@ -791,6 +845,8 @@ void ResourceManager::DetectDevicesThreadFunction() this_device_enabled = detector_settings["detectors"][detection_string]; } + LOG_DEBUG("[%s] is %s", detection_string, ((this_device_enabled == true) ? "Enabled" : "Disabled")); + if(this_device_enabled) { DetectionProgressChanged(); @@ -813,7 +869,13 @@ void ResourceManager::DetectDevicesThreadFunction() UpdateDeviceList(); } + else + { + LOG_DEBUG("[%s] no devices found", detection_string); + } prev_count = rgb_controllers_hw.size(); + + LOG_TRACE("[%s] detection end", detection_string); } } @@ -825,8 +887,6 @@ void ResourceManager::DetectDevicesThreadFunction() } else { - LOG_NOTICE("Detecting HID devices"); - /*-------------------------------------------------*\ | Iterate through all devices in list and run | | detectors | @@ -835,8 +895,12 @@ void ResourceManager::DetectDevicesThreadFunction() while(current_hid_device) { - LOG_DEBUG("HID device [%04X:%04X]", current_hid_device->vendor_id, current_hid_device->product_id); - + if(LogManager::get()->getLoglevel() >= LL_DEBUG) + { + const char* manu_name = wchar_to_char(current_hid_device->manufacturer_string); + const char* prod_name = wchar_to_char(current_hid_device->product_string); + LOG_DEBUG("[%04X:%04X U=%3X P=0x%04X I=%d] %-25s - %s", current_hid_device->vendor_id, current_hid_device->product_id, current_hid_device->usage, current_hid_device->usage_page, current_hid_device->interface_number, manu_name, prod_name); + } detection_string = ""; DetectionProgressChanged(); @@ -865,7 +929,6 @@ void ResourceManager::DetectDevicesThreadFunction() ) { detection_string = hid_device_detectors[hid_detector_idx].name.c_str(); - LOG_DEBUG("Detector found: %s", detection_string); /*-------------------------------------------------*\ | Check if this detector is enabled or needs to be | @@ -877,13 +940,23 @@ void ResourceManager::DetectDevicesThreadFunction() this_device_enabled = detector_settings["detectors"][detection_string]; } + LOG_DEBUG("[%s] is %s", detection_string, ((this_device_enabled == true) ? "Enabled" : "Disabled")); + if(this_device_enabled) { - LOG_DEBUG("Detector %s is enabled, running it", detection_string); - DetectionProgressChanged(); hid_device_detectors[hid_detector_idx].function(current_hid_device, hid_device_detectors[hid_detector_idx].name); + + if(rgb_controllers_hw.size() != prev_count) + { + LOG_VERBOSE("[%s] successfully added", detection_string); + } + else + { + LOG_INFO("[%s] is not initialized", detection_string); + } + prev_count = rgb_controllers_hw.size(); } } } @@ -912,7 +985,9 @@ void ResourceManager::DetectDevicesThreadFunction() /*-------------------------------------------------*\ | Detect other devices | \*-------------------------------------------------*/ - LOG_NOTICE("Detecting other devices"); + LOG_INFO("------------------------------------------------------"); + LOG_INFO("| Detecting other devices |"); + LOG_INFO("------------------------------------------------------"); for(unsigned int detector_idx = 0; detector_idx < device_detectors.size() && detection_is_required.load(); detector_idx++) { @@ -927,6 +1002,8 @@ void ResourceManager::DetectDevicesThreadFunction() this_device_enabled = detector_settings["detectors"][detection_string]; } + LOG_DEBUG("[%s] is %s", detection_string, ((this_device_enabled == true) ? "Enabled" : "Disabled")); + if(this_device_enabled) { DetectionProgressChanged(); @@ -950,8 +1027,14 @@ void ResourceManager::DetectDevicesThreadFunction() UpdateDeviceList(); } + else + { + LOG_DEBUG("[%s] no devices found", detection_string); + } prev_count = rgb_controllers_hw.size(); + LOG_TRACE("[%s] detection end", detection_string); + /*-------------------------------------------------*\ | Update detection percent | \*-------------------------------------------------*/ @@ -980,12 +1063,14 @@ void ResourceManager::DetectDevicesThreadFunction() DetectionEndCallbacks[callback_idx](DetectionEndCallbackArgs[callback_idx]); } - LOG_NOTICE("Detection completed"); + LOG_INFO("------------------------------------------------------"); + LOG_INFO("| Detection completed |"); + LOG_INFO("------------------------------------------------------"); } void ResourceManager::StopDeviceDetection() { - LOG_NOTICE("Detection abort requested"); + LOG_INFO("Detection abort requested"); detection_is_required = false; detection_percent = 100; detection_string = "Stopping"; @@ -1060,7 +1145,7 @@ void ResourceManager::UpdateDetectorSettings() if(save_settings) { - LOG_NOTICE("Saving detector settings"); + LOG_INFO("Saving detector settings"); settings_manager->SetSettings("Detectors", detector_settings); diff --git a/cli.cpp b/cli.cpp index 9a4003f6..f4566bf2 100644 --- a/cli.cpp +++ b/cli.cpp @@ -399,7 +399,7 @@ void OptionHelp() help_text += "--config path Use a custom path instead of the global configuration directory.\n"; help_text += "--nodetect Do not try to detect hardware at startup.\n"; help_text += "--noautoconnect Do not try to autoconnect to a local server at startup.\n"; - help_text += "--loglevel [0-6 | error | warning ...] Set the log level (0: critical to 6: debug).\n"; + help_text += "--loglevel [0-6 | error | warning ...] Set the log level (0: fatal to 6: trace).\n"; help_text += "--print-source Print the source code file and line number for each log entry.\n"; help_text += "-v, --verbose Print log messages to stdout.\n"; help_text += "-vv, --very-verbose Print debug messages and log messages to stdout.\n"; @@ -1146,38 +1146,34 @@ unsigned int cli_pre_detection(int argc, char *argv[]) try { int level = std::stoi(argument); - if (level >= 0 && level <= LL_DEBUG) + if (level >= 0 && level <= LL_TRACE) { LogManager::get()->setLoglevel(level); } else { - std::cout << "Error: Loglevel out of range: " << level << " (0-6)" << std::endl; + LOG_ERROR("Loglevel out of range: %d (0-6)", level); print_help = true; break; } } catch(std::invalid_argument& e) { - if(!strcasecmp(argument.c_str(), "critical")) + if(!strcasecmp(argument.c_str(), "fatal")) { - LogManager::get()->setLoglevel(LL_CRITICAL); + LogManager::get()->setLoglevel(LL_FATAL); } else if(!strcasecmp(argument.c_str(), "error")) { LogManager::get()->setLoglevel(LL_ERROR); } - else if(!strcasecmp(argument.c_str(), "message")) - { - LogManager::get()->setLoglevel(LL_MESSAGE); - } else if(!strcasecmp(argument.c_str(), "warning")) { LogManager::get()->setLoglevel(LL_WARNING); } - else if(!strcasecmp(argument.c_str(), "notice")) + else if(!strcasecmp(argument.c_str(), "info")) { - LogManager::get()->setLoglevel(LL_NOTICE); + LogManager::get()->setLoglevel(LL_INFO); } else if(!strcasecmp(argument.c_str(), "verbose")) { @@ -1187,9 +1183,13 @@ unsigned int cli_pre_detection(int argc, char *argv[]) { LogManager::get()->setLoglevel(LL_DEBUG); } + else if(!strcasecmp(argument.c_str(), "trace")) + { + LogManager::get()->setLoglevel(LL_TRACE); + } else { - std::cout << "Error: invalid loglevel" << std::endl; + LOG_ERROR("Invalid loglevel"); print_help = true; break; } @@ -1197,7 +1197,7 @@ unsigned int cli_pre_detection(int argc, char *argv[]) } else { - std::cout << "Error: Missing argument for --loglevel" << std::endl; + LOG_ERROR("Missing argument for --loglevel"); print_help = true; break; } @@ -1444,11 +1444,11 @@ unsigned int cli_post_detection(int argc, char *argv[]) { if(ResourceManager::get()->GetProfileManager()->SaveProfile(profile_save_filename)) { - std::cout << "Profile saved successfully" << std::endl; + LOG_INFO("Profile saved successfully"); } else { - std::cout << "Profile saving failed" << std::endl; + LOG_ERROR("Profile saving failed"); } } diff --git a/i2c_smbus/i2c_smbus_i801.cpp b/i2c_smbus/i2c_smbus_i801.cpp index e9af3063..800e9d53 100644 --- a/i2c_smbus/i2c_smbus_i801.cpp +++ b/i2c_smbus/i2c_smbus_i801.cpp @@ -491,7 +491,7 @@ void i2c_smbus_i801_detect() { if(!IsInpOutDriverOpen()) { - LOG_NOTICE("inpout32 is not loaded, i801 I2C bus detection aborted"); + LOG_INFO("inpout32 is not loaded, i801 I2C bus detection aborted"); return; } @@ -507,7 +507,7 @@ void i2c_smbus_i801_detect() if (hres) { - LOG_NOTICE("WMI query failed, i801 I2C bus detection aborted"); + LOG_INFO("WMI query failed, i801 I2C bus detection aborted"); return; } diff --git a/i2c_smbus/i2c_smbus_nct6775.cpp b/i2c_smbus/i2c_smbus_nct6775.cpp index d809cdd4..5a69708d 100644 --- a/i2c_smbus/i2c_smbus_nct6775.cpp +++ b/i2c_smbus/i2c_smbus_nct6775.cpp @@ -196,7 +196,7 @@ void i2c_smbus_nct6775_detect() { if(!IsInpOutDriverOpen()) { - LOG_NOTICE("inpout32 is not loaded, nct6775 I2C bus detection aborted"); + LOG_INFO("inpout32 is not loaded, nct6775 I2C bus detection aborted"); return; } diff --git a/i2c_smbus/i2c_smbus_piix4.cpp b/i2c_smbus/i2c_smbus_piix4.cpp index 82e7b1e2..8a74162e 100644 --- a/i2c_smbus/i2c_smbus_piix4.cpp +++ b/i2c_smbus/i2c_smbus_piix4.cpp @@ -185,7 +185,7 @@ void i2c_smbus_piix4_detect() { if(!IsInpOutDriverOpen()) { - LOG_NOTICE("inpout32 is not loaded, piix4 I2C bus detection aborted"); + LOG_INFO("inpout32 is not loaded, piix4 I2C bus detection aborted"); return; } @@ -201,7 +201,7 @@ void i2c_smbus_piix4_detect() if (hres) { - LOG_NOTICE("WMI query failed, piix4 I2C bus detection aborted"); + LOG_INFO("WMI query failed, piix4 I2C bus detection aborted"); return; } diff --git a/main.cpp b/main.cpp index 745e19cd..c2fede07 100644 --- a/main.cpp +++ b/main.cpp @@ -180,9 +180,9 @@ void MessageBoxCallback(void*, PLogMessage message) \*---------------------------------------------------------*/ switch(message->level) { - case LL_CRITICAL: box.setIcon(QMessageBox::Critical); break; + case LL_FATAL: box.setIcon(QMessageBox::Critical); break; case LL_ERROR: box.setIcon(QMessageBox::Warning); break; - case LL_MESSAGE: box.setIcon(QMessageBox::Information); break; + case LL_WARNING: box.setIcon(QMessageBox::Information); break; } /*---------------------------------------------------------*\ @@ -244,7 +244,7 @@ int main(int argc, char* argv[]) else { printf("Local OpenRGB server connected, running in client mode\r\n"); - + ResourceManager::get()->DisableDetection(); } } @@ -258,7 +258,7 @@ int main(int argc, char* argv[]) { printf("Running standalone.\r\n"); } - + ResourceManager::get()->DetectDevices(); }