From: TimePath Date: Thu, 27 Aug 2015 08:13:54 +0000 (+1000) Subject: Logging macros X-Git-Tag: xonotic-v0.8.2~2013 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d5ef5d560e367c971a2373080eceb6130ce3ed56;p=xonotic%2Fxonotic-data.pk3dir.git Logging macros --- diff --git a/qcsrc/common/notifications.qc b/qcsrc/common/notifications.qc index 2d4691021..03005da34 100644 --- a/qcsrc/common/notifications.qc +++ b/qcsrc/common/notifications.qc @@ -1960,6 +1960,12 @@ void Send_Notification( if((notif.nent_stringcount + notif.nent_floatcount) > count) { + string s = + #ifdef NOTIFICATIONS_DEBUG + Get_Notif_BroadcastName(broadcast); + #else + ftos(broadcast); + #endif backtrace(sprintf( strcat( "Not enough arguments for Send_Notification(%s, ...)! ", @@ -1967,13 +1973,8 @@ void Send_Notification( "Check the definition and function call for accuracy...?\n" ), sprintf( - #ifdef NOTIFICATIONS_DEBUG "%s, '%s', %s, %s", - Get_Notif_BroadcastName(broadcast), - #else - "%d, '%s', %s, %s", - broadcast, - #endif + s, client.classname, Get_Notif_TypeName(net_type), notif.nent_name @@ -1986,6 +1987,12 @@ void Send_Notification( } else if((notif.nent_stringcount + notif.nent_floatcount) < count) { + string s = + #ifdef NOTIFICATIONS_DEBUG + Get_Notif_BroadcastName(broadcast); + #else + ftos(broadcast); + #endif backtrace(sprintf( strcat( "Too many arguments for Send_Notification(%s, ...)! ", @@ -1993,13 +2000,8 @@ void Send_Notification( "Check the definition and function call for accuracy...?\n" ), sprintf( - #ifdef NOTIFICATIONS_DEBUG "%s, '%s', %s, %s", - Get_Notif_BroadcastName(broadcast), - #else - "%d, '%s', %s, %s", - broadcast, - #endif + s, client.classname, Get_Notif_TypeName(net_type), notif.nent_name diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index b6e2f348b..eb744a989 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -2574,29 +2574,6 @@ vector get_corner_position(entity box, float corner) } #endif -// todo: this sucks, lets find a better way to do backtraces? -void backtrace(string msg) -{ - float dev, war; - #ifdef SVQC - dev = autocvar_developer; - war = autocvar_prvm_backtraceforwarnings; - #else - dev = cvar("developer"); - war = cvar("prvm_backtraceforwarnings"); - #endif - cvar_set("developer", "1"); - cvar_set("prvm_backtraceforwarnings", "1"); - print("\n"); - print("--- CUT HERE ---\nWARNING: "); - print(msg); - print("\n"); - remove(world); // isn't there any better way to cause a backtrace? - print("\n--- CUT UNTIL HERE ---\n"); - cvar_set("developer", ftos(dev)); - cvar_set("prvm_backtraceforwarnings", ftos(war)); -} - // color code replace, place inside of sprintf and parse the string string CCR(string input) { diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index 87aa3351c..8a77ba18f 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -298,15 +298,9 @@ vector get_corner_position(entity box, float corner); #define XPD(...) __VA_ARGS__ // Some common varargs functions. Lowercase as they match C. -#define printf(...) print(sprintf(__VA_ARGS__)) -#define dprintf(...) dprint(sprintf(__VA_ARGS__)) #define fprintf(file, ...) fputs(file, sprintf(__VA_ARGS__)) #define bprintf(...) bprint(sprintf(__VA_ARGS__)) -//#ifndef MENUQC -void backtrace(string msg); -//#endif - // color code replace, place inside of sprintf and parse the string... defaults described as constants // foreground/normal colors string autocvar_hud_colorset_foreground_1 = "2"; // F1 - Green // primary priority (important names, etc) diff --git a/qcsrc/lib/Log.qh b/qcsrc/lib/Log.qh new file mode 100644 index 000000000..cd99ebf97 --- /dev/null +++ b/qcsrc/lib/Log.qh @@ -0,0 +1,60 @@ +#ifndef LOG_H +#define LOG_H + +#define _printferr(...) error(sprintf(__VA_ARGS__)) +#define _printfbt(...) backtrace(sprintf(__VA_ARGS__)) +#define printf(...) print(sprintf(__VA_ARGS__)) +#define dprintf(...) dprint(sprintf(__VA_ARGS__)) +#define _dprintf2(...) do { if (autocvar_developer > 1) dprintf(__VA_ARGS__); } while (0) + +#define _LOG(f, level, s) f("[::"level"] ["__FILE__":%s:%.0f] %s", __FUNC__, __LINE__, s) + +#define LOG_FATAL(...) _LOG_FATAL(strcat("", __VA_ARGS__)) +#define LOG_FATALF(...) _LOG_FATAL(sprintf(__VA_ARGS__)) +#define _LOG_FATAL(s) _LOG(_printferr, "FATAL", s) + +#define LOG_SEVERE(...) _LOG_SEVERE(strcat("", __VA_ARGS__)) +#define LOG_SEVEREF(...) _LOG_SEVERE(sprintf(__VA_ARGS__)) +#define _LOG_SEVERE(s) _LOG(_printfbt, "SEVERE", s) + +#define LOG_WARNING(...) _LOG_WARNING(strcat("", __VA_ARGS__)) +#define LOG_WARNINGF(...) _LOG_WARNING(sprintf(__VA_ARGS__)) +#define _LOG_WARNING(s) _LOG(printf, "WARNING", s) + +#define LOG_INFO(...) do { if (autocvar_developer) _LOG_INFO(strcat("", __VA_ARGS__)); else print (__VA_ARGS__); } while (0) +#define LOG_INFOF(...) do { if (autocvar_developer) _LOG_INFO(sprintf(__VA_ARGS__)); else printf(__VA_ARGS__); } while (0) +#define _LOG_INFO(s) _LOG(printf, "INFO", s) + +#define LOG_TRACE(...) _LOG_TRACE(strcat("", __VA_ARGS__)) +#define LOG_TRACEF(...) _LOG_TRACE(sprintf(__VA_ARGS__)) +#define _LOG_TRACE(s) _LOG(dprintf, "TRACE", s) + +#define LOG_DEBUG(...) _LOG_DEBUG(strcat("", __VA_ARGS__)) +#define LOG_DEBUGF(...) _LOG_DEBUG(sprintf(__VA_ARGS__)) +#define _LOG_DEBUG(s) _LOG(_dprintf2, "DEBUG", s) + +// TODO: this sucks, lets find a better way to do backtraces? +#ifdef SVQC +void builtin_remove(entity); +#define _backtrace() builtin_remove(NULL) +#else +void remove(entity); +#define _backtrace() remove(NULL) +#endif + +noref int autocvar_developer; +noref bool autocvar_prvm_backtraceforwarnings; + +#define backtrace(msg) do { \ + int dev = autocvar_developer; \ + bool war = autocvar_prvm_backtraceforwarnings; \ + cvar_set("developer", "1"); \ + cvar_set("prvm_backtraceforwarnings", "1"); \ + print("\n--- CUT HERE ---\n", msg, "\n"); \ + _backtrace(); \ + print("\n--- CUT UNTIL HERE ---\n"); \ + cvar_set("developer", ftos(dev)); \ + cvar_set("prvm_backtraceforwarnings", ftos(war)); \ +} while (0) + +#endif diff --git a/qcsrc/lib/_all.inc b/qcsrc/lib/_all.inc index 2c943e01b..ba432ad2a 100644 --- a/qcsrc/lib/_all.inc +++ b/qcsrc/lib/_all.inc @@ -7,6 +7,7 @@ #include "Draw.qh" #include "I18N.qh" #include "Lazy.qh" +#include "Log.qh" #include "Math.qh" #include "Nil.qh" #include "noise.qc" diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh index 63cd6379c..9d2264869 100644 --- a/qcsrc/server/autocvars.qh +++ b/qcsrc/server/autocvars.qh @@ -529,7 +529,6 @@ int autocvar_leadlimit_override; int autocvar_loddebug; int autocvar_minplayers; string autocvar_nextmap; -bool autocvar_prvm_backtraceforwarnings; string autocvar_quit_and_redirect; float autocvar_quit_and_redirect_timer; bool autocvar_quit_when_empty;