| 35 | */ |
| 36 | |
| 37 | std::string FindLogPath(const std::string &base_name) { |
| 38 | try { |
| 39 | auto &log_config = util::log::LogConfig::Instance(); |
| 40 | |
| 41 | path filename(base_name.empty() ? log_config.BaseName() : base_name); |
| 42 | |
| 43 | // Add an extension if it is missing |
| 44 | if (!filename.has_extension()) { |
| 45 | filename.replace_extension(".log"); |
| 46 | } |
| 47 | |
| 48 | // If the user supply a full path, then use the path as it is |
| 49 | if (filename.has_root_path()) { |
| 50 | return filename.string(); |
| 51 | } |
| 52 | |
| 53 | path root_dir(log_config.RootDir()); |
| 54 | // Try program data path |
| 55 | if (root_dir.empty()) { |
| 56 | root_dir = util::log::ProgramDataPath(); |
| 57 | } |
| 58 | // Still empty. Use temp path |
| 59 | if (root_dir.empty()) { |
| 60 | root_dir = temp_directory_path(); |
| 61 | } |
| 62 | std::string sub_dir = log_config.SubDir(); |
| 63 | if (!sub_dir.empty()) { |
| 64 | root_dir.append(sub_dir); |
| 65 | } |
| 66 | create_directories(root_dir); |
| 67 | |
| 68 | root_dir.append(filename.string()); |
| 69 | return root_dir.string(); |
| 70 | } catch (const std::exception &error) { |
| 71 | std::cerr << "FindLogPath(). Error: " << error.what() << std::endl; |
| 72 | throw error; // No meaning to log the error to file |
| 73 | } |
| 74 | } |
| 75 | } // namespace |
| 76 | |
| 77 | namespace util::log::detail { |
no test coverage detected