MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / FindLogPath

Function FindLogPath

lib/mdflib/mdfviewer/src/util/logfile.cpp:37–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35 */
36
37std::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
77namespace util::log::detail {

Callers 1

InitLogFileMethod · 0.85

Calls 6

ProgramDataPathFunction · 0.85
emptyMethod · 0.80
BaseNameMethod · 0.80
RootDirMethod · 0.80
SubDirMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected