diff options
Diffstat (limited to 'src/common/logging')
| -rw-r--r-- | src/common/logging/backend.cpp | 39 | ||||
| -rw-r--r-- | src/common/logging/backend.h | 16 | ||||
| -rw-r--r-- | src/common/logging/log.h | 1 |
3 files changed, 30 insertions, 26 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 04bc3128f..631f64d05 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | #include "common/logging/text_formatter.h" | 23 | #include "common/logging/text_formatter.h" |
| 24 | #include "common/string_util.h" | 24 | #include "common/string_util.h" |
| 25 | #include "common/threadsafe_queue.h" | 25 | #include "common/threadsafe_queue.h" |
| 26 | #include "core/settings.h" | ||
| 26 | 27 | ||
| 27 | namespace Log { | 28 | namespace Log { |
| 28 | 29 | ||
| @@ -113,19 +114,19 @@ private: | |||
| 113 | Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, | 114 | Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, |
| 114 | const char* function, std::string message) const { | 115 | const char* function, std::string message) const { |
| 115 | using std::chrono::duration_cast; | 116 | using std::chrono::duration_cast; |
| 117 | using std::chrono::microseconds; | ||
| 116 | using std::chrono::steady_clock; | 118 | using std::chrono::steady_clock; |
| 117 | 119 | ||
| 118 | Entry entry; | 120 | return { |
| 119 | entry.timestamp = | 121 | .timestamp = duration_cast<microseconds>(steady_clock::now() - time_origin), |
| 120 | duration_cast<std::chrono::microseconds>(steady_clock::now() - time_origin); | 122 | .log_class = log_class, |
| 121 | entry.log_class = log_class; | 123 | .log_level = log_level, |
| 122 | entry.log_level = log_level; | 124 | .filename = filename, |
| 123 | entry.filename = filename; | 125 | .line_num = line_nr, |
| 124 | entry.line_num = line_nr; | 126 | .function = function, |
| 125 | entry.function = function; | 127 | .message = std::move(message), |
| 126 | entry.message = std::move(message); | 128 | .final_entry = false, |
| 127 | 129 | }; | |
| 128 | return entry; | ||
| 129 | } | 130 | } |
| 130 | 131 | ||
| 131 | std::mutex writing_mutex; | 132 | std::mutex writing_mutex; |
| @@ -152,10 +153,19 @@ FileBackend::FileBackend(const std::string& filename) | |||
| 152 | void FileBackend::Write(const Entry& entry) { | 153 | void FileBackend::Write(const Entry& entry) { |
| 153 | // prevent logs from going over the maximum size (in case its spamming and the user doesn't | 154 | // prevent logs from going over the maximum size (in case its spamming and the user doesn't |
| 154 | // know) | 155 | // know) |
| 155 | constexpr std::size_t MAX_BYTES_WRITTEN = 50 * 1024L * 1024L; | 156 | constexpr std::size_t MAX_BYTES_WRITTEN = 100 * 1024 * 1024; |
| 156 | if (!file.IsOpen() || bytes_written > MAX_BYTES_WRITTEN) { | 157 | constexpr std::size_t MAX_BYTES_WRITTEN_EXTENDED = 1024 * 1024 * 1024; |
| 158 | |||
| 159 | if (!file.IsOpen()) { | ||
| 157 | return; | 160 | return; |
| 158 | } | 161 | } |
| 162 | |||
| 163 | if (Settings::values.extended_logging && bytes_written > MAX_BYTES_WRITTEN_EXTENDED) { | ||
| 164 | return; | ||
| 165 | } else if (!Settings::values.extended_logging && bytes_written > MAX_BYTES_WRITTEN) { | ||
| 166 | return; | ||
| 167 | } | ||
| 168 | |||
| 159 | bytes_written += file.WriteString(FormatLogMessage(entry).append(1, '\n')); | 169 | bytes_written += file.WriteString(FormatLogMessage(entry).append(1, '\n')); |
| 160 | if (entry.log_level >= Level::Error) { | 170 | if (entry.log_level >= Level::Error) { |
| 161 | file.Flush(); | 171 | file.Flush(); |
| @@ -222,6 +232,7 @@ void DebuggerBackend::Write(const Entry& entry) { | |||
| 222 | SUB(Service, NPNS) \ | 232 | SUB(Service, NPNS) \ |
| 223 | SUB(Service, NS) \ | 233 | SUB(Service, NS) \ |
| 224 | SUB(Service, NVDRV) \ | 234 | SUB(Service, NVDRV) \ |
| 235 | SUB(Service, OLSC) \ | ||
| 225 | SUB(Service, PCIE) \ | 236 | SUB(Service, PCIE) \ |
| 226 | SUB(Service, PCTL) \ | 237 | SUB(Service, PCTL) \ |
| 227 | SUB(Service, PCV) \ | 238 | SUB(Service, PCV) \ |
| @@ -274,7 +285,6 @@ const char* GetLogClassName(Class log_class) { | |||
| 274 | case Class::Count: | 285 | case Class::Count: |
| 275 | break; | 286 | break; |
| 276 | } | 287 | } |
| 277 | UNREACHABLE(); | ||
| 278 | return "Invalid"; | 288 | return "Invalid"; |
| 279 | } | 289 | } |
| 280 | 290 | ||
| @@ -293,7 +303,6 @@ const char* GetLevelName(Level log_level) { | |||
| 293 | break; | 303 | break; |
| 294 | } | 304 | } |
| 295 | #undef LVL | 305 | #undef LVL |
| 296 | UNREACHABLE(); | ||
| 297 | return "Invalid"; | 306 | return "Invalid"; |
| 298 | } | 307 | } |
| 299 | 308 | ||
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index fc338c70d..da1c2f185 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h | |||
| @@ -21,19 +21,13 @@ class Filter; | |||
| 21 | */ | 21 | */ |
| 22 | struct Entry { | 22 | struct Entry { |
| 23 | std::chrono::microseconds timestamp; | 23 | std::chrono::microseconds timestamp; |
| 24 | Class log_class; | 24 | Class log_class{}; |
| 25 | Level log_level; | 25 | Level log_level{}; |
| 26 | const char* filename; | 26 | const char* filename = nullptr; |
| 27 | unsigned int line_num; | 27 | unsigned int line_num = 0; |
| 28 | std::string function; | 28 | std::string function; |
| 29 | std::string message; | 29 | std::string message; |
| 30 | bool final_entry = false; | 30 | bool final_entry = false; |
| 31 | |||
| 32 | Entry() = default; | ||
| 33 | Entry(Entry&& o) = default; | ||
| 34 | |||
| 35 | Entry& operator=(Entry&& o) = default; | ||
| 36 | Entry& operator=(const Entry& o) = default; | ||
| 37 | }; | 31 | }; |
| 38 | 32 | ||
| 39 | /** | 33 | /** |
| @@ -100,7 +94,7 @@ public: | |||
| 100 | void Write(const Entry& entry) override; | 94 | void Write(const Entry& entry) override; |
| 101 | 95 | ||
| 102 | private: | 96 | private: |
| 103 | FileUtil::IOFile file; | 97 | Common::FS::IOFile file; |
| 104 | std::size_t bytes_written; | 98 | std::size_t bytes_written; |
| 105 | }; | 99 | }; |
| 106 | 100 | ||
diff --git a/src/common/logging/log.h b/src/common/logging/log.h index 13a4f1e30..835894918 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h | |||
| @@ -95,6 +95,7 @@ enum class Class : ClassType { | |||
| 95 | Service_NPNS, ///< The NPNS service | 95 | Service_NPNS, ///< The NPNS service |
| 96 | Service_NS, ///< The NS services | 96 | Service_NS, ///< The NS services |
| 97 | Service_NVDRV, ///< The NVDRV (Nvidia driver) service | 97 | Service_NVDRV, ///< The NVDRV (Nvidia driver) service |
| 98 | Service_OLSC, ///< The OLSC service | ||
| 98 | Service_PCIE, ///< The PCIe service | 99 | Service_PCIE, ///< The PCIe service |
| 99 | Service_PCTL, ///< The PCTL (Parental control) service | 100 | Service_PCTL, ///< The PCTL (Parental control) service |
| 100 | Service_PCV, ///< The PCV service | 101 | Service_PCV, ///< The PCV service |