diff options
author | Yuri Kunde Schlesner <yuriks@yuriks.net> | 2015-05-12 07:19:44 +0200 |
---|---|---|
committer | Yuri Kunde Schlesner <yuriks@yuriks.net> | 2015-05-12 07:31:04 +0200 |
commit | b88c91dd3d03f1a452cdd48f0db4e010cb150753 (patch) | |
tree | 17ddf674e020be69d03cc1c3c49c3e041377603b /src/common/logging/backend.cpp | |
parent | Merge pull request #748 from Subv/tls_max (diff) | |
download | yuzu-b88c91dd3d03f1a452cdd48f0db4e010cb150753.tar yuzu-b88c91dd3d03f1a452cdd48f0db4e010cb150753.tar.gz yuzu-b88c91dd3d03f1a452cdd48f0db4e010cb150753.tar.bz2 yuzu-b88c91dd3d03f1a452cdd48f0db4e010cb150753.tar.lz yuzu-b88c91dd3d03f1a452cdd48f0db4e010cb150753.tar.xz yuzu-b88c91dd3d03f1a452cdd48f0db4e010cb150753.tar.zst yuzu-b88c91dd3d03f1a452cdd48f0db4e010cb150753.zip |
Diffstat (limited to '')
-rw-r--r-- | src/common/logging/backend.cpp | 56 |
1 files changed, 9 insertions, 47 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 7d3534a43..bd2c6a153 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -3,17 +3,17 @@ // Refer to the license.txt file included. #include <algorithm> +#include <array> +#include <cstdio> -#include "common/assert.h" - +#include "common/common_funcs.h" // snprintf compatibility define #include "common/logging/backend.h" +#include "common/logging/filter.h" #include "common/logging/log.h" #include "common/logging/text_formatter.h" namespace Log { -static std::shared_ptr<Logger> global_logger; - /// Macro listing all log classes. Code should define CLS and SUB as desired before invoking this. #define ALL_LOG_CLASSES() \ CLS(Log) \ @@ -55,28 +55,8 @@ static std::shared_ptr<Logger> global_logger; SUB(Render, OpenGL) \ CLS(Loader) -Logger::Logger() { - // Register logging classes so that they can be queried at runtime - size_t parent_class; - all_classes.reserve((size_t)Class::Count); - -#define CLS(x) \ - all_classes.push_back(Class::x); \ - parent_class = all_classes.size() - 1; -#define SUB(x, y) \ - all_classes.push_back(Class::x##_##y); \ - all_classes[parent_class].num_children += 1; - - ALL_LOG_CLASSES() -#undef CLS -#undef SUB - - // Ensures that ALL_LOG_CLASSES isn't missing any entries. - DEBUG_ASSERT(all_classes.size() == (size_t)Class::Count); -} - // GetClassName is a macro defined by Windows.h, grrr... -const char* Logger::GetLogClassName(Class log_class) { +const char* GetLogClassName(Class log_class) { switch (log_class) { #define CLS(x) case Class::x: return #x; #define SUB(x, y) case Class::x##_##y: return #x "." #y; @@ -87,7 +67,7 @@ const char* Logger::GetLogClassName(Class log_class) { return "Unknown"; } -const char* Logger::GetLevelName(Level log_level) { +const char* GetLevelName(Level log_level) { #define LVL(x) case Level::x: return #x switch (log_level) { LVL(Trace); @@ -101,19 +81,6 @@ const char* Logger::GetLevelName(Level log_level) { #undef LVL } -void Logger::LogMessage(Entry entry) { - ring_buffer.Push(std::move(entry)); -} - -size_t Logger::GetEntries(Entry* out_buffer, size_t buffer_len) { - return ring_buffer.BlockingPop(out_buffer, buffer_len); -} - -std::shared_ptr<Logger> InitGlobalLogger() { - global_logger = std::make_shared<Logger>(); - return global_logger; -} - Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, const char* function, const char* format, va_list args) { @@ -138,7 +105,7 @@ Entry CreateEntry(Class log_class, Level log_level, return std::move(entry); } -static Filter* filter; +static Filter* filter = nullptr; void SetFilter(Filter* new_filter) { filter = new_filter; @@ -147,7 +114,7 @@ void SetFilter(Filter* new_filter) { void LogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_nr, const char* function, const char* format, ...) { - if (!filter->CheckMessage(log_class, log_level)) + if (filter != nullptr && !filter->CheckMessage(log_class, log_level)) return; va_list args; @@ -156,12 +123,7 @@ void LogMessage(Class log_class, Level log_level, filename, line_nr, function, format, args); va_end(args); - if (global_logger != nullptr && !global_logger->IsClosed()) { - global_logger->LogMessage(std::move(entry)); - } else { - // Fall back to directly printing to stderr - PrintMessage(entry); - } + PrintColoredMessage(entry); } } |