|
6 | 6 | #include <fstream> |
7 | 7 | #include <iostream> |
8 | 8 |
|
9 | | -std::string Logger::file = Utils::getRoamingPath() + "\\Flarial\\logs\\latest.log"; |
| 9 | +std::string Logger::file = Utils::getRoamingPath() + R"(\Flarial\logs\latest.log)"; |
10 | 10 |
|
11 | | -void Logger::writeToFile(std::string str) |
12 | | -{ |
| 11 | +void Logger::writeToFile(const std::string& str) { |
13 | 12 |
|
14 | | - if (std::filesystem::exists(file)) |
15 | | - { |
| 13 | + if (std::filesystem::exists(file)) { |
16 | 14 | std::filesystem::path p(file); |
17 | 15 | std::filesystem::create_directories(p.parent_path().string()); |
18 | 16 | } |
19 | 17 |
|
20 | 18 | CloseHandle(CreateFileA(file.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, |
21 | 19 | OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr)); |
22 | 20 |
|
23 | | - if (str.length() > 0) |
24 | | - { |
| 21 | + if (!str.empty()) { |
25 | 22 | std::ofstream fileOutput; |
26 | 23 | fileOutput.open(file.c_str(), std::ios_base::app); |
27 | 24 | fileOutput << str << std::endl; |
28 | 25 | fileOutput.close(); |
29 | 26 | } |
30 | 27 | } |
31 | 28 |
|
32 | | -void Logger::initialize() |
33 | | -{ |
34 | | - if (std::filesystem::exists(file)) |
35 | | - { |
| 29 | +void Logger::initialize() { |
| 30 | + if (std::filesystem::exists(file)) { |
36 | 31 | std::filesystem::remove(file); |
37 | 32 | } |
38 | 33 | } |
39 | 34 |
|
40 | | -void Logger::debug(std::string str) |
41 | | -{ |
| 35 | +void Logger::debug(std::string str) { |
42 | 36 | std::string log = std::format("[DEBUG]: {}", str); |
43 | 37 | std::cout << str << std::endl; |
44 | 38 | writeToFile(log); |
45 | 39 | } |
46 | 40 |
|
47 | | -void Logger::info(std::string str) |
48 | | -{ |
| 41 | +void Logger::info(std::string str) { |
49 | 42 | std::string log = std::format("[INFO]: {}", str); |
50 | 43 | std::cout << str << std::endl; |
51 | 44 | writeToFile(log); |
52 | 45 | } |
53 | 46 |
|
54 | | -void Logger::warn(std::string str) |
55 | | -{ |
| 47 | +void Logger::warn(std::string str) { |
56 | 48 | std::string log = std::format("[WARN]: {}", str); |
57 | 49 | std::cout << str << std::endl; |
58 | 50 | writeToFile(log); |
59 | 51 | } |
60 | 52 |
|
61 | | -void Logger::error(std::string str) |
62 | | -{ |
| 53 | +void Logger::error(std::string str) { |
63 | 54 | std::string log = std::format("[ERROR]: {}", str); |
64 | 55 | std::cout << str << std::endl; |
65 | 56 | writeToFile(log); |
66 | 57 | } |
67 | 58 |
|
68 | | -void Logger::fatal(std::string str) |
69 | | -{ |
| 59 | +void Logger::fatal(std::string str) { |
70 | 60 | std::string log = std::format("[FATAL]: {}", str); |
71 | 61 | std::cout << str << std::endl; |
72 | 62 | writeToFile(log); |
73 | 63 | } |
74 | 64 |
|
75 | | -void Logger::trace(std::string str) |
76 | | -{ |
| 65 | +void Logger::trace(std::string str) { |
77 | 66 | std::string log = std::format("[TRACE]: {}", str); |
78 | 67 | std::cout << str << std::endl; |
79 | 68 | writeToFile(log); |
|
0 commit comments