Change in osmo-trx[master]: logger: allow disabling all logging at compile time

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Hoernchen gerrit-no-reply at lists.osmocom.org
Mon Aug 24 23:29:45 UTC 2020


Hoernchen has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-trx/+/19804 )


Change subject: logger: allow disabling all logging at compile time
......................................................................

logger: allow disabling all logging at compile time

This will also circumvent object construction just to find out at
destruction time and after feeding the stream that there is nothing to
log anyway if logging has been disabed at compile time.

This comes at the cost of locking and unlocking the log target mutex a
third time, instead of only two times with the usual approach, since
LOGPSRCC->log_check_level() locks and unlocks the mutex while calling
should_log_to_target() just to have LOGPSRCC->logp2->osmo_vlogp do the
same while calling should_log_to_target() *again* and then maybe
actually logging somthing.

Since most log messages are disabled this change turns that into one
lock/unlock while checking and circumvents the other two lock/unlocks +
object construction.

Change-Id: I353ded020844eb4df7d7803785663789f8211d23
---
M CommonLibs/Logger.h
1 file changed, 10 insertions(+), 5 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/04/19804/1

diff --git a/CommonLibs/Logger.h b/CommonLibs/Logger.h
index b752e51..1430059 100644
--- a/CommonLibs/Logger.h
+++ b/CommonLibs/Logger.h
@@ -38,6 +38,8 @@
 #include "debug.h"
 }
 
+#define DISABLE_ALL_LOGGING false
+
 /* Translation for old log statements */
 #ifndef LOGL_ALERT
 #define LOGL_ALERT LOGL_FATAL
@@ -49,20 +51,23 @@
 #define LOGL_WARNING LOGL_NOTICE
 #endif
 
+
+#define MAYBE_LOG(src, level) if (!log_check_level(src, level) || DISABLE_ALL_LOGGING) {} else
+
 #define LOG(level) \
-	Log(DMAIN, LOGL_##level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "] "
+	MAYBE_LOG(DMAIN, LOGL_##level) Log(DMAIN, LOGL_##level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "] "
 
 #define LOGC(category, level) \
-	Log(category, LOGL_##level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "] "
+	MAYBE_LOG(category, LOGL_##level)  Log(category, LOGL_##level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "] "
 
 #define LOGLV(category, level) \
-	Log(category, level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "] "
+	MAYBE_LOG(category, level)  Log(category, level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "] "
 
 #define LOGSRC(category, level, file, line) \
-	Log(category, level, file, line).get() <<  "[tid=" << pthread_self() << "] "
+	MAYBE_LOG(category, level)  Log(category, level, file, line).get() <<  "[tid=" << pthread_self() << "] "
 
 #define LOGCHAN(chan, category, level) \
-	Log(category, LOGL_##level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "][chan=" << chan << "] "
+	MAYBE_LOG(category, LOGL_##level)  Log(category, LOGL_##level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "][chan=" << chan << "] "
 
 /**
 	A C++ stream-based thread-safe logger.

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/19804
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Change-Id: I353ded020844eb4df7d7803785663789f8211d23
Gerrit-Change-Number: 19804
Gerrit-PatchSet: 1
Gerrit-Owner: Hoernchen <ewild at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200824/1c5578c2/attachment.htm>


More information about the gerrit-log mailing list