All sleep calls via std::this_thread
[invirt/third/libt4.git] / threaded_log.cc
1 #include "t4.h"
2 #include "types.h"
3 #include "threaded_log.h"
4
5 using namespace std::chrono;
6
7 locked_ostream && _log_prefix(locked_ostream && f, const string & file, const string & func) {
8     auto thread = std::this_thread::get_id();
9     int tid = global->thread_name_map[thread];
10     if (tid==0)
11         tid = global->thread_name_map[thread] = ++global->next_thread_num;
12     auto utime = duration_cast<microseconds>(
13             system_clock::now().time_since_epoch()).count() % 1000000000;
14     f << std::setfill('0') << std::dec << std::left << std::setw(9) << utime << " ";
15     f << std::setfill(' ') << global->log_thread_prefix << std::left << std::setw(2) << tid;
16     f << " " << std::setw(20) << file << " " << std::setw(18) << func;
17     return std::move(f);
18 }
19
20 locked_ostream && _log_member(locked_ostream && f, const void *ptr) {
21     int id = global->instance_name_map[ptr];
22     if (id == 0)
23         id = global->instance_name_map[ptr] = ++global->next_instance_num;
24     f << "#" << std::left << std::setw(2) << id << " ";
25     return std::move(f);
26 }
27
28 int _log_debug_level() {
29     return global->DEBUG_LEVEL;
30 }
31
32 lock _log_lock() {
33     return lock(global->log_mutex);
34 }