diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index abff32282..aa5c4ff9d 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -13,6 +13,6 @@ assignees: '' **Version (Eg, 1.0.0, CI Build 171)** -**Logs after the crash (satdump.log)** +**Logs after the crash** (satdump.log from ~/.config/satdump or %appdata%\satdump) **Other info (Eg, Screenshots) / Files useful for debugging (CADU, etc)** diff --git a/src-core/init.cpp b/src-core/init.cpp index b6d9e139d..d268df87b 100644 --- a/src-core/init.cpp +++ b/src-core/init.cpp @@ -35,7 +35,7 @@ namespace satdump #ifdef _WIN32 if (std::filesystem::exists("satdump_cfg.json")) - user_path = "."; + user_path = "./config"; else user_path = std::string(getenv("APPDATA")) + "/satdump"; #elif __ANDROID__ diff --git a/src-core/logger.cpp b/src-core/logger.cpp index cf242e243..2bbdd84fa 100644 --- a/src-core/logger.cpp +++ b/src-core/logger.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #ifdef __ANDROID__ #include static char ag_LogTag[] = "SatDump"; @@ -11,10 +12,6 @@ static char ag_LogTag[] = "SatDump"; #include #include #endif -#ifdef __APPLE__ -#include -#include -#endif #include "init.h" @@ -151,9 +148,19 @@ namespace slog FileSink::FileSink(std::string path) { - outf = std::ofstream(path); - } + if (!std::filesystem::exists(std::filesystem::path(path).parent_path())) + std::filesystem::create_directories(std::filesystem::path(path).parent_path()); + + int suffix = 0; + std::string log_path = path + ".log"; + while(std::filesystem::exists(log_path)) + { + suffix++; + log_path = path + "-" + std::to_string(suffix) + ".log"; + } + outf = std::ofstream(log_path); + } FileSink::~FileSink() { outf.close(); @@ -278,23 +285,29 @@ void initLogger() void initFileSink() { + //Get log path try { -#ifdef __APPLE__ - char library_glob[PATH_MAX]; - glob_t globbuf; - sysdir_search_path_enumeration_state search_state = sysdir_start_search_path_enumeration(SYSDIR_DIRECTORY_LIBRARY, SYSDIR_DOMAIN_MASK_USER); - sysdir_get_next_search_path_enumeration(search_state, library_glob); - glob(library_glob, GLOB_TILDE, nullptr, &globbuf); - std::string log_path = std::string(globbuf.gl_pathv[0]) + "/Logs/satdump.log"; - globfree(&globbuf); -#elif defined(_WIN32) - std::string log_path = satdump::user_path + "/satdump.log"; -#else - std::string log_path = "satdump.log"; -#endif + //Clear old logs + char timebuffer[16]; + struct tm *timeinfo; + time_t current_time = time(NULL); + timeinfo = localtime(¤t_time); + strftime(timebuffer, sizeof(timebuffer), "%Y%m%d", timeinfo); + int delete_before = atoi(timebuffer) - 2; + for (const auto& user_file : std::filesystem::directory_iterator(satdump::user_path + "/")) + { + std::string file_name = user_file.path().filename().string(); + if (file_name.size() < 26) + continue; + int log_date = atoi(file_name.substr(8, 8).c_str()); + if (log_date != 0 && log_date < delete_before) + std::filesystem::remove(user_file); + } - file_sink = std::make_shared(log_path); + //Create new log + strftime(timebuffer, sizeof(timebuffer), "%Y%m%dT%H%M%S", timeinfo); + file_sink = std::make_shared(satdump::user_path + "/satdump-" + std::string(timebuffer)); logger->add_sink(file_sink); // file_sink->set_pattern("[%D - %T] (%L) %v"); file_sink->set_level(slog::LOG_TRACE);