38 #elif defined __APPLE__
39 #include <Carbon/Carbon.h>
47 #include <SDL_messagebox.h>
51 #if defined(__ANDROID__)
52 #include <android/log.h>
53 #ifdef SPECIAL_LOGGING
54 #define SPECIALLOG(x) __android_log_print(ANDROID_LOG_INFO, "manaplus", x);
55 #define DSPECIALLOG(x) __android_log_print(ANDROID_LOG_VERBOSE, \
58 #define SPECIALLOG(x) if (mDebugLog) \
59 __android_log_print(ANDROID_LOG_INFO, "manaplus", x);
60 #define DSPECIALLOG(x) if (mDebugLog) \
61 __android_log_print(ANDROID_LOG_VERBOSE, "manaplus", x);
63 #elif defined __native_client__
64 #ifdef SPECIAL_LOGGING
65 #define SPECIALLOG(x) std::cerr << x;
66 #define DSPECIALLOG(x) std::cerr << x;
68 #define SPECIALLOG(x) if (mDebugLog) \
70 #define DSPECIALLOG(x) if (mDebugLog) \
75 #define DSPECIALLOG(x)
82 std::string timeStr = strprintf( \
83 "[%02d:%02d:%02d.%02d]", \
84 CAST_S32(((tv.tv_sec / 60) / 60) % 24), \
85 CAST_S32((tv.tv_sec / 60) % 60), \
86 CAST_S32(tv.tv_sec % 60), \
87 CAST_S32((tv.tv_usec / 10000) % 100));
94 mMutex(SDL_CreateMutex()),
96 mLogToStandardOut(true),
98 mReportUnimplemented(false)
100 #if defined __native_client__ && defined(NACL_LOG)
101 std::cout.setf(std::ios_base::unitbuf);
127 mLogFile = fopen(logFilename.c_str(),
"wt");
132 std::cout <<
"Warning: error while opening " << logFilename <<
144 log(
"%s", str.c_str());
147 #ifdef ENABLEDEBUGLOG
155 gettimeofday(&tv,
nullptr);
180 const char*
const comment)
187 gettimeofday(&tv,
nullptr);
195 if (comment !=
nullptr)
217 if (comment !=
nullptr)
245 gettimeofday(&tv,
nullptr);
274 unsigned size = 1024;
275 if (strlen(log_text) * 3 >
size)
282 va_start(ap, log_text);
283 vsnprintf(buf,
size, log_text, ap);
289 gettimeofday(&tv,
nullptr);
321 unsigned size = 1024;
322 if (strlen(log_text) * 3 >
size)
329 va_start(ap, log_text);
330 vsnprintf(buf,
size, log_text, ap);
336 gettimeofday(&tv,
nullptr);
372 unsigned size = 1024;
373 if (strlen(log_text) * 3 >
size)
380 va_start(ap, log_text);
381 vsnprintf(buf,
size, log_text, ap);
387 gettimeofday(&tv,
nullptr);
437 log(
"Error: %s", error_text.c_str());
439 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
445 MessageBox(
nullptr, error_text.c_str(),
"Error", MB_ICONERROR | MB_OK);
446 #elif defined __APPLE__
456 #elif defined(__linux__) || defined(__linux)
457 std::cerr <<
"Error: " << error_text << std::endl;
458 const std::string
msg = std::string(
"xmessage \"").append(
459 error_text).append(
"\"");
460 if (system(
msg.c_str()) == -1)
461 std::cerr <<
"Error: " << error_text << std::endl;
464 std::cerr <<
"Error: " << error_text << std::endl;
474 log(
"Error: %s", error_text.c_str());
476 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
482 MessageBox(
nullptr, error_text.c_str(),
"Error", MB_ICONERROR | MB_OK);
483 #elif defined __APPLE__
493 #elif defined(__linux__) || defined(__linux)
494 std::cerr <<
"Error: " << error_text << std::endl;
495 const std::string
msg(
"xmessage \"Error happened. "
496 "Please see log file for more information.\"");
497 if (system(
msg.c_str()) == -1)
498 std::cerr <<
"Error: " << error_text << std::endl;
501 std::cerr <<
"Error: " << error_text << std::endl;
513 const std::string str =
strprintf(
"Unimplimented packet: %d (0x%x)",
527 "Unimplimented field value %d for packet %d (0x%x)",
537 const uint32_t id3)
const
543 "Wrong actual or planned inbound packet size!. "
544 "Packet id: %u(0x%x), Planned size: %u, Actual size: %u",
static void distributeEvent(const std::string &msg)
void log(const char *const log_text,...)
void log_r(const char *const log_text,...)
void unimplemented(const int id)
void assertLog(const char *const log_text,...)
void log1(const char *const log_text)
void safeError(const std::string &error_text) __attribute__((noreturn))
bool mReportUnimplemented
void error(const std::string &error_text) __attribute__((noreturn))
volatile bool mThreadLocked
void dlog2(const std::string &str, const int pos, const char *const comment)
void dlog(const std::string &str)
std::vector< std::string > mDelayedLog
void setLogFile(const std::string &logFilename)
bool disableLoggingInGame
#define FOR_EACH(type, iter, array)
bool msg(InputEvent &event)
std::string strprintf(const char *const format,...)