Skip to content
Snippets Groups Projects
Unverified Commit 04b9cde4 authored by bunnei's avatar bunnei Committed by GitHub
Browse files

Merge pull request #664 from jroweboy/logging-stuff

Minor logging improvements
parents 98762e96 497b8155
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <chrono> #include <chrono>
#include <climits>
#include <condition_variable> #include <condition_variable>
#include <memory> #include <memory>
#include <thread> #include <thread>
...@@ -83,8 +84,10 @@ private: ...@@ -83,8 +84,10 @@ private:
} }
}; };
while (true) { while (true) {
std::unique_lock<std::mutex> lock(message_mutex); {
message_cv.wait(lock, [&] { return !running || message_queue.Pop(entry); }); std::unique_lock<std::mutex> lock(message_mutex);
message_cv.wait(lock, [&] { return !running || message_queue.Pop(entry); });
}
if (!running) { if (!running) {
break; break;
} }
...@@ -92,7 +95,7 @@ private: ...@@ -92,7 +95,7 @@ private:
} }
// Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a case // Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a case
// where a system is repeatedly spamming logs even on close. // where a system is repeatedly spamming logs even on close.
constexpr int MAX_LOGS_TO_WRITE = 100; const int MAX_LOGS_TO_WRITE = filter.IsDebug() ? INT_MAX : 100;
int logs_written = 0; int logs_written = 0;
while (logs_written++ < MAX_LOGS_TO_WRITE && message_queue.Pop(entry)) { while (logs_written++ < MAX_LOGS_TO_WRITE && message_queue.Pop(entry)) {
write_logs(entry); write_logs(entry);
...@@ -282,4 +285,4 @@ void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename, ...@@ -282,4 +285,4 @@ void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename,
Impl::Instance().PushEntry(std::move(entry)); Impl::Instance().PushEntry(std::move(entry));
} }
} // namespace Log } // namespace Log
\ No newline at end of file
...@@ -94,4 +94,11 @@ bool Filter::ParseFilterRule(const std::string::const_iterator begin, ...@@ -94,4 +94,11 @@ bool Filter::ParseFilterRule(const std::string::const_iterator begin,
bool Filter::CheckMessage(Class log_class, Level level) const { bool Filter::CheckMessage(Class log_class, Level level) const {
return static_cast<u8>(level) >= static_cast<u8>(class_levels[static_cast<size_t>(log_class)]); return static_cast<u8>(level) >= static_cast<u8>(class_levels[static_cast<size_t>(log_class)]);
} }
bool Filter::IsDebug() const {
return std::any_of(class_levels.begin(), class_levels.end(), [](const Level& l) {
return static_cast<u8>(l) <= static_cast<u8>(Level::Debug);
});
}
} // namespace Log } // namespace Log
...@@ -47,6 +47,9 @@ public: ...@@ -47,6 +47,9 @@ public:
/// Matches class/level combination against the filter, returning true if it passed. /// Matches class/level combination against the filter, returning true if it passed.
bool CheckMessage(Class log_class, Level level) const; bool CheckMessage(Class log_class, Level level) const;
/// Returns true if any logging classes are set to debug
bool IsDebug() const;
private: private:
std::array<Level, (size_t)Class::Count> class_levels; std::array<Level, (size_t)Class::Count> class_levels;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment