X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/2546a41ad36fdc9ef6471cb35a1d56930ae1b527..ab6c1548ac2b1907bca92c8ce43e919c1a649a6f:/threaded_log.cc diff --git a/threaded_log.cc b/threaded_log.cc index 57ddc08..3218e33 100644 --- a/threaded_log.cc +++ b/threaded_log.cc @@ -1,9 +1,34 @@ -#include -#include +#include "t4.h" +#include "types.h" #include "threaded_log.h" -std::mutex cerr_mutex; -std::map thread_name_map; -int next_thread_num = 0; -std::map instance_name_map; -int next_instance_num = 0; +using namespace std::chrono; + +locked_ostream && _log_prefix(locked_ostream && f, const string & file, const string & func) { + auto thread = std::this_thread::get_id(); + int tid = global->thread_name_map[thread]; + if (tid==0) + tid = global->thread_name_map[thread] = ++global->next_thread_num; + auto utime = duration_cast( + system_clock::now().time_since_epoch()).count() % 1000000000; + f << std::setfill('0') << std::dec << std::left << std::setw(9) << utime << " "; + f << std::setfill(' ') << global->log_thread_prefix << std::left << std::setw(2) << tid; + f << " " << std::setw(20) << file << " " << std::setw(18) << func; + return std::move(f); +} + +locked_ostream && _log_member(locked_ostream && f, const void *ptr) { + int id = global->instance_name_map[ptr]; + if (id == 0) + id = global->instance_name_map[ptr] = ++global->next_instance_num; + f << "#" << std::left << std::setw(2) << id << " "; + return std::move(f); +} + +int _log_debug_level() { + return global->DEBUG_LEVEL; +} + +lock _log_lock() { + return lock(global->log_mutex); +}