X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/eb3d5c6416c0f0d1cad35e52af3231de7866fea8..c06ef44e7af1571710fd31dd0ab068dd77b1eb2d:/threaded_log.h diff --git a/threaded_log.h b/threaded_log.h index c02531e..9a83bfb 100644 --- a/threaded_log.h +++ b/threaded_log.h @@ -1,37 +1,26 @@ #ifndef threaded_log_h #define threaded_log_h -#include "types.h" - -extern mutex cerr_mutex; -extern map thread_name_map; -extern int next_thread_num; -extern map instance_name_map; -extern int next_instance_num; -extern char log_thread_prefix; +#include +#include 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 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) - -#define LOG_NONMEMBER _LOG(_log_nonmember) -#define LOG _LOG(_log_member) +int _log_debug_level(); +lock _log_lock(); -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)) +#define IF_LEVEL(level) if(_log_debug_level() >= abs(level)) #endif