From b89dc6ae0051e04f710b66e94454720f321fb14e Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Sun, 12 Jul 2020 14:22:06 +0200 Subject: [PATCH] Disable file logging for the project manager Due to `user://` returning the current working directory when no project is open, this caused logs to be written to `$HOME` most of the time. This closes #40305. --- main/main.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index bb4751c61dd..a500e173a2f 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -954,21 +954,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } #endif - GLOBAL_DEF("logging/file_logging/enable_file_logging", false); - // Only file logging by default on desktop platforms as logs can't be - // accessed easily on mobile/Web platforms (if at all). - // This also prevents logs from being created for the editor instance, as feature tags - // are disabled while in the editor (even if they should logically apply). - GLOBAL_DEF("logging/file_logging/enable_file_logging.pc", true); - GLOBAL_DEF("logging/file_logging/log_path", "user://logs/godot.log"); - GLOBAL_DEF("logging/file_logging/max_log_files", 5); - ProjectSettings::get_singleton()->set_custom_property_info("logging/file_logging/max_log_files", PropertyInfo(Variant::INT, "logging/file_logging/max_log_files", PROPERTY_HINT_RANGE, "0,20,1,or_greater")); //no negative numbers - if (FileAccess::get_create_func(FileAccess::ACCESS_USERDATA) && GLOBAL_GET("logging/file_logging/enable_file_logging")) { - String base_path = GLOBAL_GET("logging/file_logging/log_path"); - int max_files = GLOBAL_GET("logging/file_logging/max_log_files"); - OS::get_singleton()->add_logger(memnew(RotatedFileLogger(base_path, max_files))); - } - #ifdef TOOLS_ENABLED if (editor) { Engine::get_singleton()->set_editor_hint(true); @@ -985,6 +970,23 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } #endif + GLOBAL_DEF("logging/file_logging/enable_file_logging", false); + // Only file logging by default on desktop platforms as logs can't be + // accessed easily on mobile/Web platforms (if at all). + // This also prevents logs from being created for the editor instance, as feature tags + // are disabled while in the editor (even if they should logically apply). + GLOBAL_DEF("logging/file_logging/enable_file_logging.pc", true); + GLOBAL_DEF("logging/file_logging/log_path", "user://logs/godot.log"); + GLOBAL_DEF("logging/file_logging/max_log_files", 5); + ProjectSettings::get_singleton()->set_custom_property_info("logging/file_logging/max_log_files", PropertyInfo(Variant::INT, "logging/file_logging/max_log_files", PROPERTY_HINT_RANGE, "0,20,1,or_greater")); //no negative numbers + if (!project_manager && !editor && FileAccess::get_create_func(FileAccess::ACCESS_USERDATA) && GLOBAL_GET("logging/file_logging/enable_file_logging")) { + // Don't create logs for the project manager as they would be written to + // the current working directory, which is inconvenient. + String base_path = GLOBAL_GET("logging/file_logging/log_path"); + int max_files = GLOBAL_GET("logging/file_logging/max_log_files"); + OS::get_singleton()->add_logger(memnew(RotatedFileLogger(base_path, max_files))); + } + if (main_args.size() == 0 && String(GLOBAL_DEF("application/run/main_scene", "")) == "") { #ifdef TOOLS_ENABLED if (!editor && !project_manager) {