diff options
Diffstat (limited to 'src/common/logging/backend.cpp')
| -rw-r--r-- | src/common/logging/backend.cpp | 39 |
1 files changed, 24 insertions, 15 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 | ||