diff options
| author | 2015-05-15 20:54:48 -0700 | |
|---|---|---|
| committer | 2015-05-15 20:54:48 -0700 | |
| commit | ba2fe7f795ebc8da4acd247436afeefb900645d3 (patch) | |
| tree | be9a2cbcdd840f41be5353a33a98bff3ca31544e /src/common/logging/backend.h | |
| parent | Merge pull request #780 from citra-emu/roadmap (diff) | |
| parent | Remove unused concurrent_ring_buffer.h (diff) | |
| download | yuzu-ba2fe7f795ebc8da4acd247436afeefb900645d3.tar.gz yuzu-ba2fe7f795ebc8da4acd247436afeefb900645d3.tar.xz yuzu-ba2fe7f795ebc8da4acd247436afeefb900645d3.zip | |
Merge pull request #758 from yuriks/sync-logging
Common: Remove async logging
Diffstat (limited to 'src/common/logging/backend.h')
| -rw-r--r-- | src/common/logging/backend.h | 92 |
1 files changed, 12 insertions, 80 deletions
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index 3114f864c..c1f4d08e4 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h | |||
| @@ -4,17 +4,17 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <chrono> | ||
| 7 | #include <cstdarg> | 8 | #include <cstdarg> |
| 8 | #include <memory> | 9 | #include <string> |
| 9 | #include <vector> | 10 | #include <utility> |
| 10 | 11 | ||
| 11 | #include "common/concurrent_ring_buffer.h" | ||
| 12 | |||
| 13 | #include "common/logging/filter.h" | ||
| 14 | #include "common/logging/log.h" | 12 | #include "common/logging/log.h" |
| 15 | 13 | ||
| 16 | namespace Log { | 14 | namespace Log { |
| 17 | 15 | ||
| 16 | class Filter; | ||
| 17 | |||
| 18 | /** | 18 | /** |
| 19 | * A log entry. Log entries are store in a structured format to permit more varied output | 19 | * A log entry. Log entries are store in a structured format to permit more varied output |
| 20 | * formatting on different frontends, as well as facilitating filtering and aggregation. | 20 | * formatting on different frontends, as well as facilitating filtering and aggregation. |
| @@ -48,89 +48,21 @@ struct Entry { | |||
| 48 | } | 48 | } |
| 49 | }; | 49 | }; |
| 50 | 50 | ||
| 51 | struct ClassInfo { | ||
| 52 | Class log_class; | ||
| 53 | |||
| 54 | /** | ||
| 55 | * Total number of (direct or indirect) sub classes this class has. If any, they follow in | ||
| 56 | * sequence after this class in the class list. | ||
| 57 | */ | ||
| 58 | unsigned int num_children = 0; | ||
| 59 | |||
| 60 | ClassInfo(Class log_class) : log_class(log_class) {} | ||
| 61 | }; | ||
| 62 | |||
| 63 | /** | 51 | /** |
| 64 | * Logging management class. This class has the dual purpose of acting as an exchange point between | 52 | * Returns the name of the passed log class as a C-string. Subclasses are separated by periods |
| 65 | * the logging clients and the log outputter, as well as containing reflection info about available | 53 | * instead of underscores as in the enumeration. |
| 66 | * log classes. | ||
| 67 | */ | 54 | */ |
| 68 | class Logger { | 55 | const char* GetLogClassName(Class log_class); |
| 69 | private: | ||
| 70 | using Buffer = Common::ConcurrentRingBuffer<Entry, 16 * 1024 / sizeof(Entry)>; | ||
| 71 | |||
| 72 | public: | ||
| 73 | static const size_t QUEUE_CLOSED = Buffer::QUEUE_CLOSED; | ||
| 74 | |||
| 75 | Logger(); | ||
| 76 | |||
| 77 | /** | ||
| 78 | * Returns a list of all vector classes and subclasses. The sequence returned is a pre-order of | ||
| 79 | * classes and subclasses, which together with the `num_children` field in ClassInfo, allows | ||
| 80 | * you to recover the hierarchy. | ||
| 81 | */ | ||
| 82 | const std::vector<ClassInfo>& GetClasses() const { return all_classes; } | ||
| 83 | 56 | ||
| 84 | /** | 57 | /** |
| 85 | * Returns the name of the passed log class as a C-string. Subclasses are separated by periods | 58 | * Returns the name of the passed log level as a C-string. |
| 86 | * instead of underscores as in the enumeration. | 59 | */ |
| 87 | */ | 60 | const char* GetLevelName(Level log_level); |
| 88 | static const char* GetLogClassName(Class log_class); | ||
| 89 | |||
| 90 | /** | ||
| 91 | * Returns the name of the passed log level as a C-string. | ||
| 92 | */ | ||
| 93 | static const char* GetLevelName(Level log_level); | ||
| 94 | |||
| 95 | /** | ||
| 96 | * Appends a messages to the log buffer. | ||
| 97 | * @note This function is thread safe. | ||
| 98 | */ | ||
| 99 | void LogMessage(Entry entry); | ||
| 100 | |||
| 101 | /** | ||
| 102 | * Retrieves a batch of messages from the log buffer, blocking until they are available. | ||
| 103 | * @note This function is thread safe. | ||
| 104 | * | ||
| 105 | * @param out_buffer Destination buffer that will receive the log entries. | ||
| 106 | * @param buffer_len The maximum size of `out_buffer`. | ||
| 107 | * @return The number of entries stored. In case the logger is shutting down, `QUEUE_CLOSED` is | ||
| 108 | * returned, no entries are stored and the logger should shutdown. | ||
| 109 | */ | ||
| 110 | size_t GetEntries(Entry* out_buffer, size_t buffer_len); | ||
| 111 | |||
| 112 | /** | ||
| 113 | * Initiates a shutdown of the logger. This will indicate to log output clients that they | ||
| 114 | * should shutdown. | ||
| 115 | */ | ||
| 116 | void Close() { ring_buffer.Close(); } | ||
| 117 | |||
| 118 | /** | ||
| 119 | * Returns true if Close() has already been called on the Logger. | ||
| 120 | */ | ||
| 121 | bool IsClosed() const { return ring_buffer.IsClosed(); } | ||
| 122 | |||
| 123 | private: | ||
| 124 | Buffer ring_buffer; | ||
| 125 | std::vector<ClassInfo> all_classes; | ||
| 126 | }; | ||
| 127 | 61 | ||
| 128 | /// Creates a log entry by formatting the given source location, and message. | 62 | /// Creates a log entry by formatting the given source location, and message. |
| 129 | Entry CreateEntry(Class log_class, Level log_level, | 63 | Entry CreateEntry(Class log_class, Level log_level, |
| 130 | const char* filename, unsigned int line_nr, const char* function, | 64 | const char* filename, unsigned int line_nr, const char* function, |
| 131 | const char* format, va_list args); | 65 | const char* format, va_list args); |
| 132 | /// Initializes the default Logger. | ||
| 133 | std::shared_ptr<Logger> InitGlobalLogger(); | ||
| 134 | 66 | ||
| 135 | void SetFilter(Filter* filter); | 67 | void SetFilter(Filter* filter); |
| 136 | 68 | ||