game2006/server/gameserver/tracemgr.cc
aozhiwei 0535045139 1
2021-09-18 02:45:04 +00:00

51 lines
1005 B
C++

#include "precompile.h"
#include "tracemgr.h"
#ifdef DEBUG
#if __GNUC__ > 4
static void ErrorCallback(void *data, const char *msg, int errnum)
{
abort();
}
#endif
void TraceMgr::Init(const std::string& filename)
{
filename_ = filename;
#if __GNUC__ > 4
state_ = backtrace_create_state(filename_.c_str(),
0,
ErrorCallback,
nullptr);
if (!state_) {
abort();
}
#endif
log_file_ = fopen("backtrace.log", "w");
if (!log_file_) {
abort();
}
}
void TraceMgr::UnInit()
{
if (log_file_) {
fclose(log_file_);
log_file_ = nullptr;
}
}
void TraceMgr::Trace(const std::string& hint)
{
#if __GNUC__ > 4
fputs(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n", log_file_);
fputs(hint.c_str(), log_file_);
backtrace_print(state_, 0, log_file_);
fputs("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n", log_file_);
#endif
}
#endif