18 log_func = [
this](
const std::string& s)
27 std::lock_guard<std::mutex> lock(
mutex);
30 std::ofstream outfile(
filename, std::ios::out | std::ios::app);
44 std::lock_guard<std::mutex> lock(
mutex);
48 auto now = std::chrono::steady_clock::now();
50 if (std::chrono::duration_cast<std::chrono::milliseconds>(now -
last_time_logged).count() > 5000)
54 std::ofstream outfile(
filename, std::ios::out | std::ios::app);
64 std::lock_guard<std::mutex> lock(
mutex);
80 std::lock_guard<std::mutex> lock(
mutex);
86 auto now = std::chrono::system_clock::now();
87 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
89 std::time_t t = std::chrono::system_clock::to_time_t(now);
98 s <<
'[' << std::put_time(&tm,
"%Y-%m-%d %H:%M:%S")
99 <<
'.' << std::setfill(
'0') << std::setw(3) << ms.count() <<
']';
109 thread_local struct ThreadExiter
113 Logger::GetInstance().UnregisterThread(std::this_thread::get_id());
#define DEFINE_ENUM_STRINGIFYER_RANGE(Enum, min_value, max_value)
void UnregisterThread(const std::thread::id id)
Remove a thread from the map.
std::atomic< LogLevel > log_level
void RegisterThread(const std::string &name)
Register the current thread in the map.
LogLevel GetLogLevel() const
std::stringstream GetDate() const
void Log(const std::string &s)
static Logger & GetInstance()
std::chrono::steady_clock::time_point last_time_logged
std::string GetThreadName(const std::thread::id id)
Get the name of a given thread.
void SetLogLevel(const LogLevel l)
std::unordered_map< std::thread::id, std::string > thread_names
std::function< void(const std::string &)> log_func
void SetFilename(const std::string &s)
void SetLogFunc(const std::function< void(const std::string &)> &f)