4 #define _printferr(...) error(sprintf(__VA_ARGS__))
5 #define _printfbt(...) backtrace(sprintf(__VA_ARGS__))
6 #define printf(...) print(sprintf(__VA_ARGS__))
7 #define dprintf(...) dprint(sprintf(__VA_ARGS__))
8 #define _dprintf2(...) \
11 if (autocvar_developer > 1) dprintf(__VA_ARGS__); \
15 #define assert(expr, ...) _assert(LOG_WARNING, expr, __VA_ARGS__)
16 #define ASSERT(expr, ...) _assert(LOG_FATAL, expr, __VA_ARGS__)
17 #define _assert(f, expr, then) \
22 f("assertion failed: `" #expr "`\n"); \
28 #define ASSERT_LESS(name, var, const) noref int name[(const - var + 1)];
30 #define _LOG(f, level, s) f("[::"level "] ["__FILE__ ":%s:%.0f] %s", __FUNC__, __LINE__, s)
32 #define LOG_FATAL(...) _LOG_FATAL(strcat("", __VA_ARGS__))
33 #define LOG_FATALF(...) _LOG_FATAL(sprintf(__VA_ARGS__))
34 #define _LOG_FATAL(s) _LOG(_printferr, "FATAL", s)
36 #define LOG_SEVERE(...) _LOG_SEVERE(strcat("", __VA_ARGS__))
37 #define LOG_SEVEREF(...) _LOG_SEVERE(sprintf(__VA_ARGS__))
38 #define _LOG_SEVERE(s) _LOG(_printfbt, "SEVERE", s)
40 #define LOG_WARNING(...) _LOG_WARNING(strcat("", __VA_ARGS__))
41 #define LOG_WARNINGF(...) _LOG_WARNING(sprintf(__VA_ARGS__))
42 #define _LOG_WARNING(s) _LOG(printf, "WARNING", s)
44 #define LOG_INFO(...) \
47 if (autocvar_developer) _LOG_INFO(strcat("", __VA_ARGS__)); \
48 else print(__VA_ARGS__); \
51 #define LOG_INFOF(...) \
54 if (autocvar_developer) _LOG_INFO(sprintf(__VA_ARGS__)); \
55 else printf(__VA_ARGS__); \
58 #define _LOG_INFO(s) _LOG(printf, "INFO", s)
60 #define LOG_TRACE(...) _LOG_TRACE(strcat("", __VA_ARGS__))
61 #define LOG_TRACEF(...) _LOG_TRACE(sprintf(__VA_ARGS__))
62 #define _LOG_TRACE(s) _LOG(dprintf, "TRACE", s)
64 #define LOG_DEBUG(...) _LOG_DEBUG(strcat("", __VA_ARGS__))
65 #define LOG_DEBUGF(...) _LOG_DEBUG(sprintf(__VA_ARGS__))
66 #define _LOG_DEBUG(s) _LOG(_dprintf2, "DEBUG", s)
68 // TODO: this sucks, lets find a better way to do backtraces?
70 void builtin_remove(entity);
71 #define _backtrace() builtin_remove(NULL)
74 #define _backtrace() remove(NULL)
77 noref int autocvar_developer;
78 noref bool autocvar_prvm_backtraceforwarnings;
80 #define backtrace(msg) \
83 int dev = autocvar_developer; \
84 bool war = autocvar_prvm_backtraceforwarnings; \
85 cvar_set("developer", "1"); \
86 cvar_set("prvm_backtraceforwarnings", "1"); \
87 print("\n--- CUT HERE ---\n", msg, "\n"); \
89 print("\n--- CUT UNTIL HERE ---\n"); \
90 cvar_set("developer", ftos(dev)); \
91 cvar_set("prvm_backtraceforwarnings", ftos(war)); \