6 extern mutex cerr_mutex;
7 extern map<thread::id, int> thread_name_map;
8 extern int next_thread_num;
9 extern map<void *, int> instance_name_map;
10 extern int next_instance_num;
11 extern char log_thread_prefix;
14 // This... is an awful hack. But sticking this in std:: makes it possible for
15 // ostream_iterator to use it.
16 template <class A, class B>
17 ostream & operator<<(ostream &o, const pair<A,B> &d) {
18 return o << "<" << d.first << "," << d.second << ">";
23 typename enable_if<is_iterable<A>::value && !is_same<A,string>::value, ostream>::type &
24 operator<<(ostream &o, const A &a) {
26 auto oit = ostream_iterator<typename A::value_type>(o, ", ");
27 copy(a.begin(), a.end(), oit);
32 #define LOG_PREFIX { \
33 auto _thread_ = std::this_thread::get_id(); \
34 int _tid_ = thread_name_map[_thread_]; \
36 _tid_ = thread_name_map[_thread_] = ++next_thread_num; \
37 auto _utime_ = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count() % 1000000000; \
38 cerr << setfill('0') << dec << left << setw(9) << _utime_ << " "; \
39 cerr << setfill(' ') << log_thread_prefix << left << setw(2) << _tid_; \
40 cerr << " " << setw(20) << __FILE__ << " " << setw(18) << __func__; \
42 #define LOG_THIS_POINTER { \
43 int _self_ = instance_name_map[this]; \
45 _self_ = instance_name_map[this] = ++next_instance_num; \
46 cerr << "#" << setw(2) << _self_; \
49 #define LOG_NONMEMBER(_x_) { \
50 lock _cel_(cerr_mutex); \
52 cerr << _x_ << endl; \
55 lock _cel_(cerr_mutex); \
58 cerr << _x_ << endl; \