split up mutexes for performance
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
#include <print>
|
||||
#include <string_view>
|
||||
|
||||
inline std::mutex mtx;
|
||||
inline std::mutex cmtx; // console logging mutex
|
||||
inline std::mutex fmtx; // file logging mutex
|
||||
enum class LOG { INF, WRN, ERR, DBG, START };
|
||||
|
||||
template <typename... Args>
|
||||
@@ -33,18 +34,21 @@ inline void log(LOG level, std::string_view tag, std::format_string<Args...> str
|
||||
break;
|
||||
}
|
||||
|
||||
std::scoped_lock lock(mtx);
|
||||
/* log to console */
|
||||
std::print(pattern, color, tag, reset);
|
||||
std::println(str, std::forward<Args>(args)...);
|
||||
{
|
||||
std::scoped_lock lock(cmtx);
|
||||
std::print(pattern, color, tag, reset);
|
||||
std::println(str, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/* log to file */
|
||||
if (logToFile) {
|
||||
auto now = std::chrono::system_clock::now();
|
||||
std::string msg = std::format("{:%x %H:%M:%S }", floor<std::chrono::milliseconds>(now)); // timestamp
|
||||
std::format_to(std::back_inserter(msg), pattern, color, tag, reset); // tag
|
||||
std::format_to(std::back_inserter(msg), str, std::forward<Args>(args)...); // actual log message
|
||||
|
||||
std::string msg = std::format("{:%x %H:%M:%S }", floor<std::chrono::milliseconds>(now)); // timestamp
|
||||
std::format_to(std::back_inserter(msg), pattern, color, tag, reset); // tag
|
||||
std::format_to(std::back_inserter(msg), str, std::forward<Args>(args)...); // actual log message
|
||||
|
||||
std::scoped_lock lock (fmtx);
|
||||
gzFile file = gzopen("linuxSmartie.log.gz", "ab");
|
||||
if (file) {
|
||||
gzprintf(file, "%s\n", msg.c_str());
|
||||
|
||||
Reference in New Issue
Block a user