]> granicus.if.org Git - transmission/commitdiff
Reduce code duplication in logging macros
authorMike Gelfand <mikedld@mikedld.com>
Mon, 22 May 2017 20:12:57 +0000 (23:12 +0300)
committerMike Gelfand <mikedld@mikedld.com>
Mon, 22 May 2017 20:20:28 +0000 (23:20 +0300)
18 files changed:
libtransmission/announcer-http.c
libtransmission/announcer-udp.c
libtransmission/announcer.c
libtransmission/bandwidth.c
libtransmission/cache.c
libtransmission/fdlimit.c
libtransmission/handshake.c
libtransmission/log.h
libtransmission/peer-io.c
libtransmission/peer-mgr.c
libtransmission/rpc-server.c
libtransmission/rpcimpl.c
libtransmission/session.c
libtransmission/torrent-magnet.c
libtransmission/torrent.c
libtransmission/tr-utp.c
libtransmission/trevent.c
libtransmission/web.c

index 8ad64143c1b0542fde6079710554f1ad24be043b..5eec61afa6dc999113623ded6983489d5c250b01 100644 (file)
 #include "variant.h"
 #include "web.h" /* tr_http_escape() */
 
-#define dbgmsg(name, ...) \
-    do \
-    { \
-        if (tr_logGetDeepEnabled()) \
-        { \
-            tr_logAddDeep(__FILE__, __LINE__, name, __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define dbgmsg(name, ...) tr_logAddDeepNamed(name, __VA_ARGS__)
 
 /****
 *****
index 2838166a1ff73807695bc8d9aa0154bdd027aa5f..8cb2ab1d503727f75d8d652b2f9954fb54bacd58 100644 (file)
 #include "tr-udp.h"
 #include "utils.h"
 
-#define dbgmsg(name, ...) \
-    do \
-    { \
-        if (tr_logGetDeepEnabled()) \
-        { \
-            tr_logAddDeep(__FILE__, __LINE__, name, __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define dbgmsg(name, ...) tr_logAddDeepNamed(name, __VA_ARGS__)
 
 /****
 *****
index 9e1ca4cdd60ecf31beeba46f940e5ad4131c4248..2d06b6e3c81c811403b493671b7814057db23420 100644 (file)
@@ -38,7 +38,7 @@ static void tier_build_log_name(struct tr_tier const* tier, char* buf, size_t bu
         if (tr_logGetDeepEnabled()) \
         { \
             char name[128]; \
-            tier_build_log_name(tier, name, sizeof(name)); \
+            tier_build_log_name(tier, name, TR_N_ELEMENTS(name)); \
             tr_logAddDeep(__FILE__, __LINE__, name, __VA_ARGS__); \
         } \
     } \
index a1d900156357d74c1dfe68665ebf3ae7c2e8a5d8..4c55d48f6f0a4b82ed12be9ca7b95561085d08eb 100644 (file)
 #include "peer-io.h"
 #include "utils.h"
 
-#define dbgmsg(...) \
-    do \
-    { \
-        if (tr_logGetDeepEnabled()) \
-        { \
-            tr_logAddDeep(__FILE__, __LINE__, NULL, __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define dbgmsg(...) tr_logAddDeepNamed(NULL, __VA_ARGS__)
 
 /***
 ****
index daf0005f3264fae9594b91d002818914430a3314..45a43a1d8dd6421c228ffe07f290f0728eb73c8c 100644 (file)
 
 #define MY_NAME "Cache"
 
-#define dbgmsg(...) \
-    do \
-    { \
-        if (tr_logGetDeepEnabled()) \
-        { \
-            tr_logAddDeep(__FILE__, __LINE__, MY_NAME, __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define dbgmsg(...) tr_logAddDeepNamed(MY_NAME, __VA_ARGS__)
 
 /****
 *****
index fc656e59118e5c0fa556ab09b2bd1e0fb3c97b09..143fa48c348d4b3ebf393e27800a91996ccd8fff 100644 (file)
 #include "session.h"
 #include "torrent.h" /* tr_isTorrent() */
 
-#define dbgmsg(...) \
-    do \
-    { \
-        if (tr_logGetDeepEnabled()) \
-        { \
-            tr_logAddDeep(__FILE__, __LINE__, NULL, __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define dbgmsg(...) tr_logAddDeepNamed(NULL, __VA_ARGS__)
 
 /***
 ****
index 819ade15f96bd4057d5152656357c6e439c575f8..eb219d35160b3ffc08deb778fd5ac4e4cd6036ed 100644 (file)
@@ -137,15 +137,7 @@ struct tr_handshake
 ***
 **/
 
-#define dbgmsg(handshake, ...) \
-    do \
-    { \
-        if (tr_logGetDeepEnabled()) \
-        { \
-            tr_logAddDeep(__FILE__, __LINE__, tr_peerIoGetAddrStr(handshake->io), __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define dbgmsg(handshake, ...) tr_logAddDeepNamed(tr_peerIoGetAddrStr((handshake)->io), __VA_ARGS__)
 
 static char const* getStateName(handshake_state_t const state)
 {
index 1c83cdce7ef2ab6acfba55a5aca4dc1f2c56269b..4493cedaf47dcc81d9fa27384e9332d6eab2a001 100644 (file)
@@ -30,104 +30,50 @@ static inline bool tr_logLevelIsActive(tr_log_level level)
 void tr_logAddMessage(char const* file, int line, tr_log_level level, char const* torrent, char const* fmt, ...)
     TR_GNUC_PRINTF(5, 6);
 
-#define tr_logAddNamedError(n, ...) \
+#define tr_logAddNamed(level, name, ...) \
     do \
     { \
-        if (tr_logLevelIsActive(TR_LOG_ERROR)) \
+        if (tr_logLevelIsActive(level)) \
         { \
-            tr_logAddMessage(__FILE__, __LINE__, TR_LOG_ERROR, n, __VA_ARGS__); \
+            tr_logAddMessage(__FILE__, __LINE__, level, name, __VA_ARGS__); \
         } \
     } \
     while (0)
 
-#define tr_logAddNamedInfo(n, ...) \
-    do \
-    { \
-        if (tr_logLevelIsActive(TR_LOG_INFO)) \
-        { \
-            tr_logAddMessage(__FILE__, __LINE__, TR_LOG_INFO, n, __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define tr_logAddNamedError(name, ...) tr_logAddNamed(TR_LOG_ERROR, name, __VA_ARGS__)
+#define tr_logAddNamedInfo(name, ...) tr_logAddNamed(TR_LOG_INFO, name, __VA_ARGS__)
+#define tr_logAddNamedDbg(name, ...) tr_logAddNamed(TR_LOG_DEBUG, name, __VA_ARGS__)
 
-#define tr_logAddNamedDbg(n, ...) \
-    do \
-    { \
-        if (tr_logLevelIsActive(TR_LOG_DEBUG)) \
-        { \
-            tr_logAddMessage(__FILE__, __LINE__, TR_LOG_DEBUG, n, __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define tr_logAddTor(level, tor, ...) tr_logAddNamed(level, tr_torrentName(tor), __VA_ARGS__)
 
-#define tr_logAddTorErr(tor, ...) \
-    do \
-    { \
-        if (tr_logLevelIsActive(TR_LOG_ERROR)) \
-        { \
-            tr_logAddMessage(__FILE__, __LINE__, TR_LOG_ERROR, tr_torrentName(tor), __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define tr_logAddTorErr(tor, ...) tr_logAddTor(TR_LOG_ERROR, tor, __VA_ARGS__)
+#define tr_logAddTorInfo(tor, ...) tr_logAddTor(TR_LOG_INFO, tor, __VA_ARGS__)
+#define tr_logAddTorDbg(tor, ...) tr_logAddTor(TR_LOG_DEBUG, tor, __VA_ARGS__)
 
-#define tr_logAddTorInfo(tor, ...) \
-    do \
-    { \
-        if (tr_logLevelIsActive(TR_LOG_INFO)) \
-        { \
-            tr_logAddMessage(__FILE__, __LINE__, TR_LOG_INFO, tr_torrentName(tor), __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define tr_logAdd(level, ...) tr_logAddNamed(level, NULL, __VA_ARGS__)
 
-#define tr_logAddTorDbg(tor, ...) \
-    do \
-    { \
-        if (tr_logLevelIsActive(TR_LOG_DEBUG)) \
-        { \
-            tr_logAddMessage(__FILE__, __LINE__, TR_LOG_DEBUG, tr_torrentName(tor), __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define tr_logAddError(...) tr_logAdd(TR_LOG_ERROR, __VA_ARGS__)
+#define tr_logAddInfo(...) tr_logAdd(TR_LOG_INFO, __VA_ARGS__)
+#define tr_logAddDebug(...) tr_logAdd(TR_LOG_DEBUG, __VA_ARGS__)
 
-#define tr_logAddError(...) \
-    do \
-    { \
-        if (tr_logLevelIsActive(TR_LOG_ERROR)) \
-        { \
-            tr_logAddMessage(__FILE__, __LINE__, TR_LOG_ERROR, NULL, __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+tr_sys_file_t tr_logGetFile(void);
 
-#define tr_logAddInfo(...) \
-    do \
-    { \
-        if (tr_logLevelIsActive(TR_LOG_INFO)) \
-        { \
-            tr_logAddMessage(__FILE__, __LINE__, TR_LOG_INFO, NULL, __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+/** @brief return true if deep logging has been enabled by the user; false otherwise */
+bool tr_logGetDeepEnabled(void);
 
-#define tr_logAddDebug(...) \
+void tr_logAddDeep(char const* file, int line, char const* name, char const* fmt, ...) TR_GNUC_PRINTF(4, 5)
+    TR_GNUC_NONNULL(1, 4);
+
+#define tr_logAddDeepNamed(name, ...) \
     do \
     { \
-        if (tr_logLevelIsActive(TR_LOG_DEBUG)) \
+        if (tr_logGetDeepEnabled()) \
         { \
-            tr_logAddMessage(__FILE__, __LINE__, TR_LOG_DEBUG, NULL, __VA_ARGS__); \
+            tr_logAddDeep(__FILE__, __LINE__, name, __VA_ARGS__); \
         } \
     } \
     while (0)
 
-tr_sys_file_t tr_logGetFile(void);
-
-/** @brief return true if deep logging has been enabled by the user; false otherwise */
-bool tr_logGetDeepEnabled(void);
-
-void tr_logAddDeep(char const* file, int line, char const* name, char const* fmt, ...) TR_GNUC_PRINTF(4, 5)
-    TR_GNUC_NONNULL(1, 4);
-
 /** @brief set the buffer with the current time formatted for deep logging. */
 char* tr_logGetTimeStr(char* buf, size_t buflen) TR_GNUC_NONNULL(1);
 
index 4a3430eb0a455639d1e70283af606bd04cfe608e..4b27b5d45e66858935c28a572fdb7a50dced3ab4 100644 (file)
@@ -69,15 +69,7 @@ static size_t guessPacketOverhead(size_t d)
 ***
 **/
 
-#define dbgmsg(io, ...) \
-    do \
-    { \
-        if (tr_logGetDeepEnabled()) \
-        { \
-            tr_logAddDeep(__FILE__, __LINE__, tr_peerIoGetAddrStr(io), __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define dbgmsg(io, ...) tr_logAddDeepNamed(tr_peerIoGetAddrStr(io), __VA_ARGS__)
 
 /**
 ***
index 73eadb0ef3f29b3d2825c340c4841281985df673..ccd7441da74bd13a4189bc09d23d1aca7c55786f 100644 (file)
@@ -221,25 +221,9 @@ struct tr_peerMgr
     struct event* atomTimer;
 };
 
-#define tordbg(t, ...) \
-    do \
-    { \
-        if (tr_logGetDeepEnabled()) \
-        { \
-            tr_logAddDeep(__FILE__, __LINE__, tr_torrentName(t->tor), __VA_ARGS__); \
-        } \
-    } \
-    while (0)
-
-#define dbgmsg(...) \
-    do \
-    { \
-        if (tr_logGetDeepEnabled()) \
-        { \
-            tr_logAddDeep(__FILE__, __LINE__, NULL, __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define tordbg(t, ...) tr_logAddDeepNamed(tr_torrentName((t)->tor), __VA_ARGS__)
+
+#define dbgmsg(...) tr_logAddDeepNamed(NULL, __VA_ARGS__)
 
 /**
 *** tr_peer virtual functions
index dd1f70040507017fc5d44873c163d4252f8b67a5..80a77228dd6f399d3e1ac3a2f172660d5b9a7221 100644 (file)
@@ -67,15 +67,7 @@ struct tr_rpc_server
     z_stream stream;
 };
 
-#define dbgmsg(...) \
-    do \
-    { \
-        if (tr_logGetDeepEnabled()) \
-        { \
-            tr_logAddDeep(__FILE__, __LINE__, MY_NAME, __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define dbgmsg(...) tr_logAddDeepNamed(MY_NAME, __VA_ARGS__)
 
 /***
 ****
index af92ea434b03d99cada3306ca9bfb6590d7e7804..6012ec89472c2c6a252758e2710a167d6bc7be3b 100644 (file)
 #define RECENTLY_ACTIVE_SECONDS 60
 
 #if 0
-
-#define dbgmsg(fmt, ...) \
-    do \
-    { \
-        fprintf(stderr, "%s:%d"#fmt, __FILE__, __LINE__, __VA_ARGS__); \
-        fprintf(stderr, "\n"); \
-    } \
-    while (0)
-
+#define dbgmsg(fmt, ...) fprintf(stderr, "%s:%d " fmt "\n", __FILE__, __LINE__, __VA_ARGS__)
 #else
-
-#define dbgmsg(...) \
-    do \
-    { \
-        if (tr_logGetDeepEnabled()) \
-        { \
-            tr_logAddDeep(__FILE__, __LINE__, "RPC", __VA_ARGS__); \
-        } \
-    } \
-    while (0)
-
+#define dbgmsg(...) tr_logAddDeepNamed("RPC", __VA_ARGS__)
 #endif
 
 /***
index be711f87502e1a1da4e8140e91eeb33a225883b5..c18ff1b21ce3b7e6b4e5e2a7d49ae15b9be5e56b 100644 (file)
@@ -71,15 +71,7 @@ enum
     SAVE_INTERVAL_SECS = 360
 };
 
-#define dbgmsg(...) \
-    do \
-    { \
-        if (tr_logGetDeepEnabled()) \
-        { \
-            tr_logAddDeep(__FILE__, __LINE__, NULL, __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define dbgmsg(...) tr_logAddDeepNamed(NULL, __VA_ARGS__)
 
 static tr_port getRandomPort(tr_session* s)
 {
index 07d1e97f239e6c7d9ac11b7fd66f43d635ac0b25..3ac8cc0b05c3db68241f2183716cb37d2f9a9461 100644 (file)
 #include "variant.h"
 #include "web.h"
 
-#define dbgmsg(tor, ...) \
-    do \
-    { \
-        if (tr_logGetDeepEnabled()) \
-        { \
-            tr_logAddDeep(__FILE__, __LINE__, tr_torrentName(tor), __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define dbgmsg(tor, ...) tr_logAddDeepNamed(tr_torrentName(tor), __VA_ARGS__)
 
 /***
 ****
index 68bb2885756fcb4714e8bea0ef84c8a8130270cc..3e91614007cb1c8500ce16dc628aba1b42bc1b8b 100644 (file)
 ****
 ***/
 
-#define tr_deeplog_tor(tor, ...) \
-    do \
-    { \
-        if (tr_logGetDeepEnabled()) \
-        { \
-            tr_logAddDeep(__FILE__, __LINE__, tr_torrentName(tor), __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define tr_deeplog_tor(tor, ...) tr_logAddDeepNamed(tr_torrentName(tor), __VA_ARGS__)
 
 /***
 ****
index 3ab795ec2cab15dd71f745a718b5bf2188cae2ce..c6abe5b621e45440c6feffdd2a1d7e621b4fa179 100644 (file)
@@ -38,15 +38,7 @@ THE SOFTWARE.
 
 #define MY_NAME "UTP"
 
-#define dbgmsg(...) \
-    do \
-    { \
-        if (tr_logGetDeepEnabled()) \
-        { \
-            tr_logAddDeep(__FILE__, __LINE__, MY_NAME, __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define dbgmsg(...) tr_logAddDeepNamed(MY_NAME, __VA_ARGS__)
 
 #ifndef WITH_UTP
 
index ee915bf5e95f3e6df65ee8f823d19d53fd857dce..15404ca41b6e009d4c5bf4c3c2d2847367f7aa5d 100644 (file)
@@ -166,15 +166,7 @@ struct tr_run_data
     void* user_data;
 };
 
-#define dbgmsg(...) \
-    do \
-    { \
-        if (tr_logGetDeepEnabled()) \
-        { \
-            tr_logAddDeep(__FILE__, __LINE__, "event", __VA_ARGS__); \
-        } \
-    } \
-    while (0)
+#define dbgmsg(...) tr_logAddDeepNamed("event", __VA_ARGS__)
 
 static void readFromPipe(evutil_socket_t fd, short eventType, void* veh)
 {
index 46bd0ef46771b74704e6366994254cd8220a6b22..8da1e0be7b7fcf8231fa8c45ae65ebe8e091389c 100644 (file)
@@ -42,27 +42,9 @@ enum
 };
 
 #if 0
-
-#define dbgmsg(...) \
-    do \
-    { \
-        fprintf(stderr, __VA_ARGS__); \
-        fprintf(stderr, "\n"); \
-    } \
-    while (0)
-
+#define dbgmsg(fmt, ...) fprintf(stderr, fmt "\n", __VA_ARGS__)
 #else
-
-#define dbgmsg(...) \
-    do \
-    { \
-        if (tr_logGetDeepEnabled()) \
-        { \
-            tr_logAddDeep(__FILE__, __LINE__, "web", __VA_ARGS__); \
-        } \
-    } \
-    while (0)
-
+#define dbgmsg(...) tr_logAddDeepNamed("web", __VA_ARGS__)
 #endif
 
 /***