diff options
Diffstat (limited to 'src/common/logging/backend.h')
| -rw-r--r-- | src/common/logging/backend.h | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index eb629a33f..4b9a910c1 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h | |||
| @@ -1,43 +1,32 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | 1 | // Copyright 2014 Citra Emulator Project |
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | |||
| 4 | #pragma once | 5 | #pragma once |
| 5 | 6 | ||
| 6 | #include <chrono> | ||
| 7 | #include <filesystem> | 7 | #include <filesystem> |
| 8 | #include <memory> | 8 | #include <memory> |
| 9 | #include <string> | 9 | #include <string> |
| 10 | #include <string_view> | 10 | #include <string_view> |
| 11 | #include "common/fs/file.h" | ||
| 12 | #include "common/logging/filter.h" | 11 | #include "common/logging/filter.h" |
| 13 | #include "common/logging/log.h" | 12 | #include "common/logging/log.h" |
| 14 | 13 | ||
| 14 | namespace Common::FS { | ||
| 15 | class IOFile; | ||
| 16 | } | ||
| 17 | |||
| 15 | namespace Common::Log { | 18 | namespace Common::Log { |
| 16 | 19 | ||
| 17 | class Filter; | 20 | class Filter; |
| 18 | 21 | ||
| 19 | /** | 22 | /** |
| 20 | * A log entry. Log entries are store in a structured format to permit more varied output | ||
| 21 | * formatting on different frontends, as well as facilitating filtering and aggregation. | ||
| 22 | */ | ||
| 23 | struct Entry { | ||
| 24 | std::chrono::microseconds timestamp; | ||
| 25 | Class log_class{}; | ||
| 26 | Level log_level{}; | ||
| 27 | const char* filename = nullptr; | ||
| 28 | unsigned int line_num = 0; | ||
| 29 | std::string function; | ||
| 30 | std::string message; | ||
| 31 | bool final_entry = false; | ||
| 32 | }; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * Interface for logging backends. As loggers can be created and removed at runtime, this can be | 23 | * Interface for logging backends. As loggers can be created and removed at runtime, this can be |
| 36 | * used by a frontend for adding a custom logging backend as needed | 24 | * used by a frontend for adding a custom logging backend as needed |
| 37 | */ | 25 | */ |
| 38 | class Backend { | 26 | class Backend { |
| 39 | public: | 27 | public: |
| 40 | virtual ~Backend() = default; | 28 | virtual ~Backend() = default; |
| 29 | |||
| 41 | virtual void SetFilter(const Filter& new_filter) { | 30 | virtual void SetFilter(const Filter& new_filter) { |
| 42 | filter = new_filter; | 31 | filter = new_filter; |
| 43 | } | 32 | } |
| @@ -53,6 +42,8 @@ private: | |||
| 53 | */ | 42 | */ |
| 54 | class ConsoleBackend : public Backend { | 43 | class ConsoleBackend : public Backend { |
| 55 | public: | 44 | public: |
| 45 | ~ConsoleBackend() override; | ||
| 46 | |||
| 56 | static const char* Name() { | 47 | static const char* Name() { |
| 57 | return "console"; | 48 | return "console"; |
| 58 | } | 49 | } |
| @@ -67,6 +58,8 @@ public: | |||
| 67 | */ | 58 | */ |
| 68 | class ColorConsoleBackend : public Backend { | 59 | class ColorConsoleBackend : public Backend { |
| 69 | public: | 60 | public: |
| 61 | ~ColorConsoleBackend() override; | ||
| 62 | |||
| 70 | static const char* Name() { | 63 | static const char* Name() { |
| 71 | return "color_console"; | 64 | return "color_console"; |
| 72 | } | 65 | } |
| @@ -83,6 +76,7 @@ public: | |||
| 83 | class FileBackend : public Backend { | 76 | class FileBackend : public Backend { |
| 84 | public: | 77 | public: |
| 85 | explicit FileBackend(const std::filesystem::path& filename); | 78 | explicit FileBackend(const std::filesystem::path& filename); |
| 79 | ~FileBackend() override; | ||
| 86 | 80 | ||
| 87 | static const char* Name() { | 81 | static const char* Name() { |
| 88 | return "file"; | 82 | return "file"; |
| @@ -95,7 +89,7 @@ public: | |||
| 95 | void Write(const Entry& entry) override; | 89 | void Write(const Entry& entry) override; |
| 96 | 90 | ||
| 97 | private: | 91 | private: |
| 98 | FS::IOFile file; | 92 | std::unique_ptr<FS::IOFile> file; |
| 99 | std::size_t bytes_written = 0; | 93 | std::size_t bytes_written = 0; |
| 100 | }; | 94 | }; |
| 101 | 95 | ||
| @@ -104,6 +98,8 @@ private: | |||
| 104 | */ | 98 | */ |
| 105 | class DebuggerBackend : public Backend { | 99 | class DebuggerBackend : public Backend { |
| 106 | public: | 100 | public: |
| 101 | ~DebuggerBackend() override; | ||
| 102 | |||
| 107 | static const char* Name() { | 103 | static const char* Name() { |
| 108 | return "debugger"; | 104 | return "debugger"; |
| 109 | } | 105 | } |
| @@ -120,17 +116,6 @@ void RemoveBackend(std::string_view backend_name); | |||
| 120 | Backend* GetBackend(std::string_view backend_name); | 116 | Backend* GetBackend(std::string_view backend_name); |
| 121 | 117 | ||
| 122 | /** | 118 | /** |
| 123 | * Returns the name of the passed log class as a C-string. Subclasses are separated by periods | ||
| 124 | * instead of underscores as in the enumeration. | ||
| 125 | */ | ||
| 126 | const char* GetLogClassName(Class log_class); | ||
| 127 | |||
| 128 | /** | ||
| 129 | * Returns the name of the passed log level as a C-string. | ||
| 130 | */ | ||
| 131 | const char* GetLevelName(Level log_level); | ||
| 132 | |||
| 133 | /** | ||
| 134 | * The global filter will prevent any messages from even being processed if they are filtered. Each | 119 | * The global filter will prevent any messages from even being processed if they are filtered. Each |
| 135 | * backend can have a filter, but if the level is lower than the global filter, the backend will | 120 | * backend can have a filter, but if the level is lower than the global filter, the backend will |
| 136 | * never get the message | 121 | * never get the message |