diff --git a/LogManager.cpp b/LogManager.cpp index 979948cf..d9d3e660 100644 --- a/LogManager.cpp +++ b/LogManager.cpp @@ -24,6 +24,7 @@ LogManager::LogManager() { base_clock = std::chrono::steady_clock::now(); log_console_enabled = false; + log_file_enabled = true; } LogManager* LogManager::get() @@ -64,63 +65,71 @@ void LogManager::configure(json config, const filesystem::path& defaultDir) \*-------------------------------------------------*/ if(!log_stream.is_open()) { - std::string logname = "OpenRGB_#.log"; - - /*-------------------------------------------------*\ - | If the logfile is defined in the configuration, | - | use the configured name | - \*-------------------------------------------------*/ - if(config.contains("logfile")) + if(config.contains("log_file")) { - const json& logfile_obj = config["logfile"]; - if(logfile_obj.is_string()) + log_file_enabled = config["log_file"]; + } + + if(log_file_enabled) + { + std::string logname = "OpenRGB_#.log"; + + /*-------------------------------------------------*\ + | If the logfile is defined in the configuration, | + | use the configured name | + \*-------------------------------------------------*/ + if(config.contains("logfile")) { - std::string tmpname = config["logfile"]; - if(!tmpname.empty()) + const json& logfile_obj = config["logfile"]; + if(logfile_obj.is_string()) { - logname = tmpname; + std::string tmpname = config["logfile"]; + if(!tmpname.empty()) + { + logname = tmpname; + } } } + + /*-------------------------------------------------*\ + | If the # symbol is found in the log file name, | + | replace it with a timestamp | + \*-------------------------------------------------*/ + time_t t = time(0); + struct tm* tmp = localtime(&t); + char time_string[64]; + snprintf(time_string, 64, "%04d%02d%02d_%02d%02d%02d", 1900 + tmp->tm_year, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + + size_t oct = logname.find("#"); + if(oct != logname.npos) + { + logname.replace(oct, 1, time_string); + } + + /*-------------------------------------------------*\ + | If the path is relative, use logs dir | + \*-------------------------------------------------*/ + filesystem::path p = filesystem::u8path(logname); + if(p.is_relative()) + { + p = defaultDir / "logs" / logname; + } + filesystem::create_directories(p.parent_path()); + + /*-------------------------------------------------*\ + | Open the logfile | + \*-------------------------------------------------*/ + log_stream.open(p); + + /*-------------------------------------------------*\ + | Print Git Commit info, version, etc. | + \*-------------------------------------------------*/ + log_stream << " OpenRGB v" << VERSION_STRING << std::endl; + log_stream << " Commit: " << GIT_COMMIT_ID << " from " << GIT_COMMIT_DATE << std::endl; + log_stream << " Launched: " << time_string << std::endl; + log_stream << "====================================================================================================" << std::endl; + log_stream << std::endl; } - - /*-------------------------------------------------*\ - | If the # symbol is found in the log file name, | - | replace it with a timestamp | - \*-------------------------------------------------*/ - time_t t = time(0); - struct tm* tmp = localtime(&t); - char time_string[64]; - snprintf(time_string, 64, "%04d%02d%02d_%02d%02d%02d", 1900 + tmp->tm_year, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); - - size_t oct = logname.find("#"); - if(oct != logname.npos) - { - logname.replace(oct, 1, time_string); - } - - /*-------------------------------------------------*\ - | If the path is relative, use logs dir | - \*-------------------------------------------------*/ - filesystem::path p = filesystem::u8path(logname); - if(p.is_relative()) - { - p = defaultDir / "logs" / logname; - } - filesystem::create_directories(p.parent_path()); - - /*-------------------------------------------------*\ - | Open the logfile | - \*-------------------------------------------------*/ - log_stream.open(p); - - /*-------------------------------------------------*\ - | Print Git Commit info, version, etc. | - \*-------------------------------------------------*/ - log_stream << " OpenRGB v" << VERSION_STRING << std::endl; - log_stream << " Commit: " << GIT_COMMIT_ID << " from " << GIT_COMMIT_DATE << std::endl; - log_stream << " Launched: " << time_string << std::endl; - log_stream << "====================================================================================================" << std::endl; - log_stream << std::endl; } /*-------------------------------------------------*\ @@ -183,12 +192,12 @@ void LogManager::_flush() | Clear temp message buffers after writing them out | \*-------------------------------------------------*/ temp_messages.clear(); - } - /*-------------------------------------------------*\ - | Flush the stream | - \*-------------------------------------------------*/ - log_stream.flush(); + /*-------------------------------------------------*\ + | Flush the stream | + \*-------------------------------------------------*/ + log_stream.flush(); + } } void LogManager::flush() diff --git a/LogManager.h b/LogManager.h index ba3f1183..55e656b8 100644 --- a/LogManager.h +++ b/LogManager.h @@ -107,6 +107,7 @@ public: std::vector messages(); bool log_console_enabled; + bool log_file_enabled; static const char* log_codes[]; }; diff --git a/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.cpp b/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.cpp index 86af79f6..543a1817 100644 --- a/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.cpp +++ b/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.cpp @@ -186,10 +186,23 @@ OpenRGBSettingsPage::OpenRGBSettingsPage(QWidget *parent) : /*---------------------------------------------------------*\ | Checkboxes | \*---------------------------------------------------------*/ + if(log_manager_settings.contains("log_file")) + { + ui->CheckboxLogFile->setChecked(log_manager_settings["log_file"]); + } + else + { + ui->CheckboxLogFile->setChecked(true); + } + if(log_manager_settings.contains("log_console")) { ui->CheckboxLogConsole->setChecked(log_manager_settings["log_console"]); } + else + { + ui->CheckboxLogConsole->setChecked(false); + } /*---------------------------------------------------------*\ | Load drivers settings (Windows only) | @@ -946,6 +959,14 @@ void Ui::OpenRGBSettingsPage::on_CheckboxLogConsole_clicked() SaveSettings(); } +void Ui::OpenRGBSettingsPage::on_CheckboxLogFile_clicked() +{ + json log_manager_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("LogManager"); + log_manager_settings["log_file"] = ui->CheckboxLogFile->isChecked(); + ResourceManager::get()->GetSettingsManager()->SetSettings("LogManager", log_manager_settings); + SaveSettings(); +} + void Ui::OpenRGBSettingsPage::on_CheckboxAMDSMBusReduceCPU_clicked() { json drivers_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Drivers"); diff --git a/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.h b/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.h index 4e33aa83..641e006a 100644 --- a/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.h +++ b/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.h @@ -78,6 +78,7 @@ private slots: void on_CheckboxRunZoneChecks_clicked(); void on_OpenSettingsFolderButton_clicked(); void on_CheckboxLogConsole_clicked(); + void on_CheckboxLogFile_clicked(); void on_CheckboxAMDSMBusReduceCPU_clicked(); void on_CheckboxSharedSMBusAccess_clicked(); diff --git a/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.ui b/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.ui index 638d1a15..a3fcec7c 100644 --- a/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.ui +++ b/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.ui @@ -31,29 +31,36 @@ 0 0 - 441 - 856 + 460 + 950 - - + + - Load Profile - - - - - - - Custom Arguments + Minimize On Close - + - Start At Login + Start At Login Settings: + + + + + + + AMD SMBus: Reduce CPU Usage (restart required) + + + + + + + Start Server @@ -64,54 +71,39 @@ - - + + - AMD SMBus: Reduce CPU Usage (restart required) + Disable key expansion in device view - - + + - Start At Login Settings: + Enable Log Console (restart required) - - + + - Start Server + Save Geometry On Close - - - - Set Profile on Exit - - + + - - - - Theme (restart required) - - + + - - - - - - Show LED view by default - - - - + + + @@ -119,41 +111,10 @@ - - + + - - - - Enable Log Console (restart required) - - - - - - - - - - Start Client - - - - - - - Disable key expansion in device view - - - - - - - Start at Login Status - - - - + Qt::Vertical @@ -169,72 +130,62 @@ - - - - - - - Save Geometry On Close - - - - - - - Minimize On Close - - - - - - - Start Minimized - - - - - - - User Interface Settings: - - - - - - - - - - Shared SMBus Access (restart required) - - - - - - - Drivers Settings - - - - - - - + Set Server Port - - + + - Load Window Geometry + Start at Login Status + + + + + + + Shared SMBus Access (restart required) + + + + + + + Start Client + + + + + + Load Profile + + + + + + + Set Profile on Exit + + + + + + + Hex Format + + + + + + + 90000 @@ -247,6 +198,44 @@ + + + + Theme (restart required) + + + + + + + Show LED view by default + + + + + + + Set Profile on Suspend + + + + + + + Set Server Host + + + + + + + + + + Start Minimized + + + @@ -254,6 +243,30 @@ + + + + User Interface Settings: + + + + + + + + + + Set Profile on Resume + + + + + + + Drivers Settings + + + @@ -261,42 +274,36 @@ - - + + - Set Server Host - - - - - - - Hex Format - - - - - - - - - - Set Profile on Suspend + Custom Arguments - + - - + + - Set Profile on Resume + Load Window Geometry - - + + + + Start At Login + + + + + + + Enable Log File (restart required) + +