]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Logging macros
authorTimePath <andrew.hardaker1995@gmail.com>
Thu, 27 Aug 2015 08:13:54 +0000 (18:13 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Thu, 27 Aug 2015 08:13:54 +0000 (18:13 +1000)
qcsrc/common/notifications.qc
qcsrc/common/util.qc
qcsrc/common/util.qh
qcsrc/lib/Log.qh [new file with mode: 0644]
qcsrc/lib/_all.inc
qcsrc/server/autocvars.qh

index 2d4691021245085ca693016da1372ddb0838d7d6..03005da3432bfea9fe1778c78f1eb1746b0fcdeb 100644 (file)
@@ -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
index b6e2f348b7753a8bd3aeb1c9d4924161c171f7b6..eb744a98949ae5ccdc4d2325b8359a1998521fdf 100644 (file)
@@ -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)
 {
index 87aa3351c7096fef68be94847aaa827ab9a50092..8a77ba18ffdcc7b9fdeeb712f4e3a08ed699a68a 100644 (file)
@@ -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 (file)
index 0000000..cd99ebf
--- /dev/null
@@ -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
index 2c943e01bcfaab3444a4230d64ba53eed321542b..ba432ad2a08cfa4f2b4833722ca1bc9190e6e018 100644 (file)
@@ -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"
index 63cd6379c8bd537c99bc1cbbbb53462c104de64e..9d226486921a994eb0100fb682aa350d75670a28 100644 (file)
@@ -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;