diff --git a/src/logger.cpp b/src/logger.cpp index 02ca7f6..30e912d 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -1,4 +1,5 @@ #include "logger.hpp" +#include #include #include #include @@ -6,18 +7,21 @@ using namespace sc; +std::mutex logger::_mtx; + logger::logger(const std::string& name, loglevel level) : _level(level), _name(name) {} void logger::msg(loglevel level, const sc::io::trgb* color, const char* file, int line, const char* func) { if (level >= _level) { + std::lock_guard lock {_mtx}; if (_topcall) { write_prefix(level, color, file, line, func); } else { _topcall = true; } - std::cerr << '\n'; + std::cerr << std::endl; if (color) { std::cerr << sc::io::reset; } diff --git a/src/logger.hpp b/src/logger.hpp index c29d456..9f6b6dc 100644 --- a/src/logger.hpp +++ b/src/logger.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace sc { @@ -66,6 +67,7 @@ namespace sc { loglevel _level {loglevel::info}; bool _topcall {true}; std::string _name; + static std::mutex _mtx; }; }