#include "types.h"
-extern mutex cerr_mutex;
-extern map<thread::id, int> thread_name_map;
-extern int next_thread_num;
-extern map<const void *, int> instance_name_map;
-extern int next_instance_num;
extern char log_thread_prefix;
+extern int DEBUG_LEVEL;
struct locked_ostream {
- ostream & s;
+ std::ostream & s;
lock l;
- ~locked_ostream() { s << endl; }
+ locked_ostream(locked_ostream &&) = default;
+ ~locked_ostream() { s << std::endl; }
template <typename U>
locked_ostream & operator<<(U && u) { s << u; return *this; }
-
- typedef std::ostream& (*ostream_manipulator)(ostream&);
- locked_ostream & operator<<(ostream_manipulator manip) { s << manip; return *this; }
};
locked_ostream && _log_prefix(locked_ostream && f, const string & file, const string & func);
locked_ostream && _log_member(locked_ostream && f, const void *ptr);
-#define _log_nonmember(f, ptr) f
-
-#define _LOG(_context_) _context_(_log_prefix(locked_ostream{cerr, lock(cerr_mutex)}, __FILE__, __func__), (const void *)this)
+lock _log_lock();
-#define LOG_NONMEMBER _LOG(_log_nonmember)
-#define LOG _LOG(_log_member)
-
-extern int DEBUG_LEVEL;
+#define LOG_NONMEMBER _log_prefix(locked_ostream{std::cerr, _log_lock()}, __FILE__, __func__)
+#define LOG _log_member(LOG_NONMEMBER, (const void *)this)
#define IF_LEVEL(level) if(DEBUG_LEVEL >= abs(level))