Bug 809950 - fix mtransport logging macros to not introduce static initializers; r=jesup

This commit is contained in:
Nathan Froyd 2012-11-08 13:44:41 -05:00
parent 60b2718413
commit 453525f9d9

View File

@ -12,31 +12,19 @@
#include <sstream>
#include <prlog.h>
#include "mozilla/Scoped.h"
namespace mozilla {
class LogCtx {
public:
LogCtx(const char* name) : module_(PR_NewLogModule(name)) {}
LogCtx(std::string& name) : module_(PR_NewLogModule(name.c_str())) {}
PRLogModuleInfo* module() const { return module_; }
private:
PRLogModuleInfo* module_;
};
#define MOZ_MTLOG_MODULE(n) \
static ScopedDeletePtr<LogCtx> mlog_ctx; \
static const char *mlog_name = n
static PRLogModuleInfo* getLogModule() { \
static PRLogModuleInfo* log; \
if (!log) \
log = PR_NewLogModule(n); \
return log; \
}
#define MOZ_MTLOG(level, b) \
do { if (!mlog_ctx) mlog_ctx = new LogCtx(mlog_name); \
if (mlog_ctx) { \
do { \
std::stringstream str; \
str << b; \
PR_LOG(mlog_ctx->module(), level, ("%s", str.str().c_str())); }} while(0)
} // close namespace
PR_LOG(getLogModule(), level, ("%s", str.str().c_str())); } while(0)
#endif