impr: Optimize includes in logger
This commit is contained in:
parent
e984fde966
commit
b31ae6e690
@ -2,13 +2,11 @@
|
||||
|
||||
#include <hex.hpp>
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/color.h>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
#include <hex/helpers/fmt.hpp>
|
||||
#include <wolv/utils/guards.hpp>
|
||||
|
||||
namespace hex::log {
|
||||
|
||||
@ -20,10 +18,12 @@ namespace hex::log {
|
||||
[[maybe_unused]] void redirectToFile();
|
||||
[[maybe_unused]] void enableColorPrinting();
|
||||
|
||||
[[nodiscard]] std::recursive_mutex& getLoggerMutex();
|
||||
[[nodiscard]] bool isLoggingSuspended();
|
||||
[[nodiscard]] bool isDebugLoggingEnabled();
|
||||
|
||||
void lockLoggerMutex();
|
||||
void unlockLoggerMutex();
|
||||
|
||||
struct LogEntry {
|
||||
std::string project;
|
||||
std::string level;
|
||||
@ -39,7 +39,8 @@ namespace hex::log {
|
||||
if (isLoggingSuspended()) [[unlikely]]
|
||||
return;
|
||||
|
||||
std::scoped_lock lock(getLoggerMutex());
|
||||
lockLoggerMutex();
|
||||
ON_SCOPE_EXIT { unlockLoggerMutex(); };
|
||||
|
||||
auto dest = getDestination();
|
||||
try {
|
||||
@ -94,7 +95,8 @@ namespace hex::log {
|
||||
}
|
||||
|
||||
[[maybe_unused]] void print(const std::string &fmt, auto && ... args) {
|
||||
std::scoped_lock lock(impl::getLoggerMutex());
|
||||
impl::lockLoggerMutex();
|
||||
ON_SCOPE_EXIT { impl::unlockLoggerMutex(); };
|
||||
|
||||
try {
|
||||
auto dest = impl::getDestination();
|
||||
@ -105,7 +107,8 @@ namespace hex::log {
|
||||
}
|
||||
|
||||
[[maybe_unused]] void println(const std::string &fmt, auto && ... args) {
|
||||
std::scoped_lock lock(impl::getLoggerMutex());
|
||||
impl::lockLoggerMutex();
|
||||
ON_SCOPE_EXIT { impl::unlockLoggerMutex(); };
|
||||
|
||||
try {
|
||||
auto dest = impl::getDestination();
|
||||
@ -115,4 +118,4 @@ namespace hex::log {
|
||||
} catch (const std::exception&) { }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,15 @@
|
||||
#include <hex/helpers/logger.hpp>
|
||||
|
||||
#include <hex/api/task_manager.hpp>
|
||||
#include <hex/api/event_manager.hpp>
|
||||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/helpers/fmt.hpp>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
#include <mutex>
|
||||
#include <chrono>
|
||||
#include <fmt/chrono.h>
|
||||
#include <hex/api/task_manager.hpp>
|
||||
|
||||
#if defined(OS_WINDOWS)
|
||||
#include <Windows.h>
|
||||
@ -40,10 +41,15 @@ namespace hex::log {
|
||||
|
||||
namespace impl {
|
||||
|
||||
std::recursive_mutex& getLoggerMutex() {
|
||||
return s_loggerMutex;
|
||||
void lockLoggerMutex() {
|
||||
s_loggerMutex.lock();
|
||||
}
|
||||
|
||||
void unlockLoggerMutex() {
|
||||
s_loggerMutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
bool isLoggingSuspended() {
|
||||
return s_loggingSuspended;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user