<p>Hoernchen has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-trx/+/19804">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">logger: allow disabling all logging at compile time<br><br>This will also circumvent object construction just to find out at<br>destruction time and after feeding the stream that there is nothing to<br>log anyway if logging has been disabed at compile time.<br><br>This comes at the cost of locking and unlocking the log target mutex a<br>third time, instead of only two times with the usual approach, since<br>LOGPSRCC->log_check_level() locks and unlocks the mutex while calling<br>should_log_to_target() just to have LOGPSRCC->logp2->osmo_vlogp do the<br>same while calling should_log_to_target() *again* and then maybe<br>actually logging somthing.<br><br>Since most log messages are disabled this change turns that into one<br>lock/unlock while checking and circumvents the other two lock/unlocks +<br>object construction.<br><br>Change-Id: I353ded020844eb4df7d7803785663789f8211d23<br>---<br>M CommonLibs/Logger.h<br>1 file changed, 10 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/04/19804/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/CommonLibs/Logger.h b/CommonLibs/Logger.h</span><br><span>index b752e51..1430059 100644</span><br><span>--- a/CommonLibs/Logger.h</span><br><span>+++ b/CommonLibs/Logger.h</span><br><span>@@ -38,6 +38,8 @@</span><br><span> #include "debug.h"</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#define DISABLE_ALL_LOGGING false</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Translation for old log statements */</span><br><span> #ifndef LOGL_ALERT</span><br><span> #define LOGL_ALERT LOGL_FATAL</span><br><span>@@ -49,20 +51,23 @@</span><br><span> #define LOGL_WARNING LOGL_NOTICE</span><br><span> #endif</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define MAYBE_LOG(src, level) if (!log_check_level(src, level) || DISABLE_ALL_LOGGING) {} else</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #define LOG(level) \</span><br><span style="color: hsl(0, 100%, 40%);">-     Log(DMAIN, LOGL_##level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "] "</span><br><span style="color: hsl(120, 100%, 40%);">+   MAYBE_LOG(DMAIN, LOGL_##level) Log(DMAIN, LOGL_##level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "] "</span><br><span> </span><br><span> #define LOGC(category, level) \</span><br><span style="color: hsl(0, 100%, 40%);">-       Log(category, LOGL_##level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "] "</span><br><span style="color: hsl(120, 100%, 40%);">+        MAYBE_LOG(category, LOGL_##level)  Log(category, LOGL_##level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "] "</span><br><span> </span><br><span> #define LOGLV(category, level) \</span><br><span style="color: hsl(0, 100%, 40%);">-       Log(category, level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "] "</span><br><span style="color: hsl(120, 100%, 40%);">+       MAYBE_LOG(category, level)  Log(category, level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "] "</span><br><span> </span><br><span> #define LOGSRC(category, level, file, line) \</span><br><span style="color: hsl(0, 100%, 40%);">-        Log(category, level, file, line).get() <<  "[tid=" << pthread_self() << "] "</span><br><span style="color: hsl(120, 100%, 40%);">+    MAYBE_LOG(category, level)  Log(category, level, file, line).get() <<  "[tid=" << pthread_self() << "] "</span><br><span> </span><br><span> #define LOGCHAN(chan, category, level) \</span><br><span style="color: hsl(0, 100%, 40%);">-  Log(category, LOGL_##level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "][chan=" << chan << "] "</span><br><span style="color: hsl(120, 100%, 40%);">+     MAYBE_LOG(category, LOGL_##level)  Log(category, LOGL_##level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "][chan=" << chan << "] "</span><br><span> </span><br><span> /**</span><br><span>      A C++ stream-based thread-safe logger.</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-trx/+/19804">change 19804</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/osmo-trx/+/19804"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-trx </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I353ded020844eb4df7d7803785663789f8211d23 </div>
<div style="display:none"> Gerrit-Change-Number: 19804 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Hoernchen <ewild@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>