Make useLogThread a per-severity option and default Error to false (#2473)
This commit is contained in:
@@ -9,6 +9,7 @@ enum class EventSeverity : uint8_t {
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
SeverityCount
|
||||
};
|
||||
|
||||
enum class Event : uint8_t {
|
||||
|
||||
@@ -39,6 +39,7 @@ public:
|
||||
~Log();
|
||||
|
||||
static void useLogThread(bool enable) noexcept;
|
||||
static void useLogThread(bool enable, EventSeverity) noexcept;
|
||||
|
||||
template <typename... Args>
|
||||
static void Debug(Event event, Args&&... args) noexcept {
|
||||
|
||||
@@ -29,6 +29,8 @@ public:
|
||||
case EventSeverity::Error:
|
||||
MLNLogError(message);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <mbgl/util/enum.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
#include <mbgl/util/platform.hpp>
|
||||
#include <mbgl/util/traits.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdarg>
|
||||
@@ -14,7 +15,8 @@ namespace mbgl {
|
||||
namespace {
|
||||
|
||||
std::unique_ptr<Log::Observer> currentObserver;
|
||||
std::atomic<bool> useThread(true);
|
||||
constexpr auto SeverityCount = underlying_type(EventSeverity::SeverityCount);
|
||||
std::atomic<bool> useThread[SeverityCount] = {true, true, true, false};
|
||||
std::mutex mutex;
|
||||
|
||||
} // namespace
|
||||
@@ -25,7 +27,7 @@ public:
|
||||
: scheduler(Scheduler::GetSequenced()) {}
|
||||
|
||||
void record(EventSeverity severity, Event event, int64_t code, const std::string& msg) try {
|
||||
if (useThread) {
|
||||
if (useThread[underlying_type(severity)]) {
|
||||
auto threadName = platform::getCurrentThreadName();
|
||||
scheduler->schedule([=]() { Log::record(severity, event, code, msg, threadName); });
|
||||
} else {
|
||||
@@ -55,7 +57,17 @@ Log* Log::get() noexcept {
|
||||
}
|
||||
|
||||
void Log::useLogThread(bool enable) noexcept {
|
||||
useThread = enable;
|
||||
useLogThread(enable, EventSeverity::Debug);
|
||||
useLogThread(enable, EventSeverity::Info);
|
||||
useLogThread(enable, EventSeverity::Warning);
|
||||
useLogThread(enable, EventSeverity::Error);
|
||||
}
|
||||
|
||||
void Log::useLogThread(bool enable, EventSeverity severity) noexcept {
|
||||
const auto index = underlying_type(severity);
|
||||
if (index < SeverityCount) {
|
||||
useThread[index] = enable;
|
||||
}
|
||||
}
|
||||
|
||||
void Log::setObserver(std::unique_ptr<Observer> observer) {
|
||||
|
||||
Reference in New Issue
Block a user