diff options
| author | 2021-06-13 07:52:02 -0400 | |
|---|---|---|
| committer | 2021-06-13 11:05:58 -0400 | |
| commit | 8150c65c07c39ab842f8c3249464ece1af4db9b4 (patch) | |
| tree | 8526f7bac5febb719665c3be957d93be6784f9ed /src/common/logging/backend.cpp | |
| parent | Merge pull request #6452 from german77/sixaxis_firmware_stub (diff) | |
| download | yuzu-8150c65c07c39ab842f8c3249464ece1af4db9b4.tar.gz yuzu-8150c65c07c39ab842f8c3249464ece1af4db9b4.tar.xz yuzu-8150c65c07c39ab842f8c3249464ece1af4db9b4.zip | |
common: logging: backend: Wrap IOFile in a unique_ptr
Allows us to forward declare Common::FS::IOFile.
Diffstat (limited to 'src/common/logging/backend.cpp')
| -rw-r--r-- | src/common/logging/backend.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 6aa8ac960..756b08dfe 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | #endif | 17 | #endif |
| 18 | 18 | ||
| 19 | #include "common/assert.h" | 19 | #include "common/assert.h" |
| 20 | #include "common/fs/file.h" | ||
| 20 | #include "common/fs/fs.h" | 21 | #include "common/fs/fs.h" |
| 21 | #include "common/logging/backend.h" | 22 | #include "common/logging/backend.h" |
| 22 | #include "common/logging/log.h" | 23 | #include "common/logging/log.h" |
| @@ -140,10 +141,14 @@ private: | |||
| 140 | std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()}; | 141 | std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()}; |
| 141 | }; | 142 | }; |
| 142 | 143 | ||
| 144 | ConsoleBackend::~ConsoleBackend() = default; | ||
| 145 | |||
| 143 | void ConsoleBackend::Write(const Entry& entry) { | 146 | void ConsoleBackend::Write(const Entry& entry) { |
| 144 | PrintMessage(entry); | 147 | PrintMessage(entry); |
| 145 | } | 148 | } |
| 146 | 149 | ||
| 150 | ColorConsoleBackend::~ColorConsoleBackend() = default; | ||
| 151 | |||
| 147 | void ColorConsoleBackend::Write(const Entry& entry) { | 152 | void ColorConsoleBackend::Write(const Entry& entry) { |
| 148 | PrintColoredMessage(entry); | 153 | PrintColoredMessage(entry); |
| 149 | } | 154 | } |
| @@ -157,16 +162,19 @@ FileBackend::FileBackend(const std::filesystem::path& filename) { | |||
| 157 | void(FS::RemoveFile(old_filename)); | 162 | void(FS::RemoveFile(old_filename)); |
| 158 | void(FS::RenameFile(filename, old_filename)); | 163 | void(FS::RenameFile(filename, old_filename)); |
| 159 | 164 | ||
| 160 | file = FS::IOFile(filename, FS::FileAccessMode::Write, FS::FileType::TextFile); | 165 | file = |
| 166 | std::make_unique<FS::IOFile>(filename, FS::FileAccessMode::Write, FS::FileType::TextFile); | ||
| 161 | } | 167 | } |
| 162 | 168 | ||
| 169 | FileBackend::~FileBackend() = default; | ||
| 170 | |||
| 163 | void FileBackend::Write(const Entry& entry) { | 171 | void FileBackend::Write(const Entry& entry) { |
| 164 | // prevent logs from going over the maximum size (in case its spamming and the user doesn't | 172 | // prevent logs from going over the maximum size (in case its spamming and the user doesn't |
| 165 | // know) | 173 | // know) |
| 166 | constexpr std::size_t MAX_BYTES_WRITTEN = 100 * 1024 * 1024; | 174 | constexpr std::size_t MAX_BYTES_WRITTEN = 100 * 1024 * 1024; |
| 167 | constexpr std::size_t MAX_BYTES_WRITTEN_EXTENDED = 1024 * 1024 * 1024; | 175 | constexpr std::size_t MAX_BYTES_WRITTEN_EXTENDED = 1024 * 1024 * 1024; |
| 168 | 176 | ||
| 169 | if (!file.IsOpen()) { | 177 | if (!file->IsOpen()) { |
| 170 | return; | 178 | return; |
| 171 | } | 179 | } |
| 172 | 180 | ||
| @@ -176,12 +184,14 @@ void FileBackend::Write(const Entry& entry) { | |||
| 176 | return; | 184 | return; |
| 177 | } | 185 | } |
| 178 | 186 | ||
| 179 | bytes_written += file.WriteString(FormatLogMessage(entry).append(1, '\n')); | 187 | bytes_written += file->WriteString(FormatLogMessage(entry).append(1, '\n')); |
| 180 | if (entry.log_level >= Level::Error) { | 188 | if (entry.log_level >= Level::Error) { |
| 181 | void(file.Flush()); | 189 | void(file->Flush()); |
| 182 | } | 190 | } |
| 183 | } | 191 | } |
| 184 | 192 | ||
| 193 | DebuggerBackend::~DebuggerBackend() = default; | ||
| 194 | |||
| 185 | void DebuggerBackend::Write(const Entry& entry) { | 195 | void DebuggerBackend::Write(const Entry& entry) { |
| 186 | #ifdef _WIN32 | 196 | #ifdef _WIN32 |
| 187 | ::OutputDebugStringW(UTF8ToUTF16W(FormatLogMessage(entry).append(1, '\n')).c_str()); | 197 | ::OutputDebugStringW(UTF8ToUTF16W(FormatLogMessage(entry).append(1, '\n')).c_str()); |