[MERGED] osmo-trx[master]: Logger: get rid of alarm APIs

Harald Welte gerrit-no-reply at lists.osmocom.org
Wed Feb 21 12:00:16 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: Logger: get rid of alarm APIs
......................................................................


Logger: get rid of alarm APIs

It's only used internally inside the Logger module, and in case there's
an "alarm" (level more than critical) we still print on cerr, so we can
just rely on our system catching stderr instead of stdout to handle it.

Change-Id: I6d6df1578c3a4c1a37bd0d69952d443f62eed2ab
---
M CommonLibs/Logger.cpp
M CommonLibs/Logger.h
M tests/CommonLibs/LogTest.cpp
M tests/CommonLibs/LogTest.ok
4 files changed, 0 insertions(+), 97 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/CommonLibs/Logger.cpp b/CommonLibs/Logger.cpp
index ee607fd..4bfb782 100644
--- a/CommonLibs/Logger.cpp
+++ b/CommonLibs/Logger.cpp
@@ -35,8 +35,6 @@
 #include "Logger.h"
 #include "Threads.h"	// pat added
 
-#define MAX_ALARMS 20
-
 using namespace std;
 
 // Switches to enable/disable logging targets
@@ -47,26 +45,6 @@
 
 // Global log level threshold:
 int config_log_level;
-
-/**@ The global alarms table. */
-//@{
-Mutex           alarmsLock;
-list<string>    alarmsList;
-void            addAlarm(const string&);
-//@}
-
-
-
-// (pat) If Log messages are printed before the classes in this module are inited
-// (which happens when static classes have constructors that do work)
-// the OpenBTS just crashes.
-// Prevent that by setting sLoggerInited to true when this module is inited.
-static bool sLoggerInited = 0;
-static struct CheckLoggerInitStatus {
-	CheckLoggerInitStatus() { sLoggerInited = 1; }
-} sCheckloggerInitStatus;
-
-
 
 /** Names of the logging levels. */
 const char *levelNames[] = {
@@ -119,36 +97,11 @@
 	return os << ss.str();
 }
 
-// copies the alarm list and returns it. list supposed to be small.
-list<string> gGetLoggerAlarms()
-{
-    alarmsLock.lock();
-    list<string> ret;
-    // excuse the "complexity", but to use std::copy with a list you need
-    // an insert_iterator - copy technically overwrites, doesn't insert.
-    insert_iterator< list<string> > ii(ret, ret.begin());
-    copy(alarmsList.begin(), alarmsList.end(), ii);
-    alarmsLock.unlock();
-    return ret;
-}
-
-/** Add an alarm to the alarm list. */
-void addAlarm(const string& s)
-{
-    alarmsLock.lock();
-    alarmsList.push_back(s);
-    while (alarmsList.size() > MAX_ALARMS) alarmsList.pop_front();
-    alarmsLock.unlock();
-}
-
-
 Log::~Log()
 {
 	if (mDummyInit) return;
 	// Anything at or above LOG_CRIT is an "alarm".
-	// Save alarms in the local list and echo them to stderr.
 	if (mPriority <= LOG_ERR) {
-		if (sLoggerInited) addAlarm(mStream.str().c_str());
 		cerr << mStream.str() << endl;
 	}
 	// Current logging level was already checked by the macro. So just log.
diff --git a/CommonLibs/Logger.h b/CommonLibs/Logger.h
index ef11932..7b208fa 100644
--- a/CommonLibs/Logger.h
+++ b/CommonLibs/Logger.h
@@ -103,10 +103,6 @@
 extern bool gLogToConsole;	// Output log messages to stdout
 extern bool gLogToSyslog;	// Output log messages to syslog
 
-
-
-std::list<std::string> gGetLoggerAlarms();		///< Get a copy of the recent alarm list.
-
 const std::string timestr();		// A timestamp to print in messages.
 std::ostream& operator<<(std::ostream& os, std::ostringstream& ss);
 
diff --git a/tests/CommonLibs/LogTest.cpp b/tests/CommonLibs/LogTest.cpp
index f64041d..5d1dd2c 100644
--- a/tests/CommonLibs/LogTest.cpp
+++ b/tests/CommonLibs/LogTest.cpp
@@ -29,14 +29,6 @@
 
 #include "Logger.h"
 
-void printAlarms()
-{
-    std::ostream_iterator<std::string> output( std::cout, "\n" );
-    std::list<std::string> alarms = gGetLoggerAlarms();
-    std::cout << "# alarms = " << alarms.size() << std::endl;
-    std::copy( alarms.begin(), alarms.end(), output );
-}
-
 int main(int argc, char *argv[])
 {
 	gLogInit("LogTest","NOTICE",LOG_LOCAL7);
@@ -49,14 +41,8 @@
 	Log(LOG_NOTICE).get() << " testing the logger.";
 	Log(LOG_INFO).get() << " testing the logger.";
         Log(LOG_DEBUG).get() << " testing the logger.";
-    std::cout << "\n\n\n";
-    std::cout << "testing Alarms\n";
-    std::cout << "you should see three lines:" << std::endl;
-    printAlarms();
     std::cout << "----------- generating 20 alarms ----------" << std::endl;
     for (int i = 0 ; i < 20 ; ++i) {
         Log(LOG_ALERT).get() << i;
     }
-    std::cout << "you should see ten lines with the numbers 10..19:" << std::endl;
-    printAlarms();
 }
diff --git a/tests/CommonLibs/LogTest.ok b/tests/CommonLibs/LogTest.ok
index e1211b0..ac60314 100644
--- a/tests/CommonLibs/LogTest.ok
+++ b/tests/CommonLibs/LogTest.ok
@@ -6,39 +6,7 @@
 NOTICE  testing the logger.
 INFO  testing the logger.
 DEBUG  testing the logger.
-
-
-
-testing Alarms
-you should see three lines:
-# alarms = 4
-EMERG  testing the logger.
-ALERT  testing the logger.
-CRIT  testing the logger.
-ERR  testing the logger.
 ----------- generating 20 alarms ----------
-ALERT 0
-ALERT 1
-ALERT 2
-ALERT 3
-ALERT 4
-ALERT 5
-ALERT 6
-ALERT 7
-ALERT 8
-ALERT 9
-ALERT 10
-ALERT 11
-ALERT 12
-ALERT 13
-ALERT 14
-ALERT 15
-ALERT 16
-ALERT 17
-ALERT 18
-ALERT 19
-you should see ten lines with the numbers 10..19:
-# alarms = 20
 ALERT 0
 ALERT 1
 ALERT 2

-- 
To view, visit https://gerrit.osmocom.org/6612
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6d6df1578c3a4c1a37bd0d69952d443f62eed2ab
Gerrit-PatchSet: 1
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder


More information about the gerrit-log mailing list