6 #if defined(unix) || defined(__unix__) || defined(__APPLE__)
12 #define UI_MSG_TIMEOUT 4000
14 enum { LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_FATAL, LOG_DEBUG };
16 static int typecolor(int type);
18 static FILE *fp = stdout;
20 static void logmsg(int type, const char *fmt, va_list ap)
22 #if defined(unix) || defined(__unix__) || (defined(__APPLE__) && !defined(TARGET_IPHONE))
23 if(isatty(fileno(fp)) && type != LOG_INFO) {
24 int c = typecolor(type);
25 fprintf(fp, "\033[%dm", c);
26 vfprintf(fp, fmt, ap);
27 fprintf(fp, "\033[0m");
31 vfprintf(fp, fmt, ap);
33 if(type == LOG_ERROR || type == LOG_FATAL || type == LOG_DEBUG) {
38 if(type == LOG_FATAL) {
39 static char msgbuf[1024];
40 vsnprintf(msgbuf, sizeof msgbuf - 1, fmt, ap);
41 msgbuf[sizeof msgbuf - 1] = 0;
42 MessageBox(0, msgbuf, "Fatal error", MB_OK | MB_ICONSTOP);
47 extern "C" void info_log(const char *fmt, ...)
52 logmsg(LOG_INFO, fmt, ap);
56 extern "C" void warning_log(const char *fmt, ...)
61 logmsg(LOG_WARNING, fmt, ap);
65 show_messagev(UI_MSG_TIMEOUT, Vec3(1.0, 0.8, 0.1), fmt, ap);
69 extern "C" void error_log(const char *fmt, ...)
74 logmsg(LOG_ERROR, fmt, ap);
78 show_messagev(UI_MSG_TIMEOUT, Vec3(1.0, 0.1, 0.1), fmt, ap);
82 extern "C" void fatal_log(const char *fmt, ...)
87 logmsg(LOG_FATAL, fmt, ap);
91 extern "C" void debug_log(const char *fmt, ...)
96 logmsg(LOG_DEBUG, fmt, ap);
111 #define ANSI_FGCOLOR(x) (30 + (x))
112 #define ANSI_BGCOLOR(x) (40 + (x))
114 static int typecolor(int type)
118 return ANSI_FGCOLOR(RED);
120 return ANSI_FGCOLOR(RED); // TODO differentiate from LOG_ERROR
122 return ANSI_FGCOLOR(YELLOW);
124 return ANSI_FGCOLOR(MAGENTA);