aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2018-01-09 14:49:33 +0100
committerPau Espin Pedrol <pespin@sysmocom.de>2018-01-09 15:26:49 +0100
commitf3837d26f9856e3989c2916c8f64a030f050c001 (patch)
tree20563e59dfe4ed3fc4f8724fe90cba5021a52dfc
parentddf4743306fe431110cfd2370227183202dac441 (diff)
Logger: Stop using Log.File and Log.Level from config
This is a required step towards getting rid of ConfigurationTable class and libsqlite dependency. As a side effect, support for different log levels for different files is dropped, but it's not something really being used and we will end up dropping current logging system in favour of osmocom's one in the future anyway. Change-Id: I51cb12d1ab7e103e78190ac71a70fb5bb1d9ff51
-rw-r--r--CommonLibs/Logger.cpp102
-rw-r--r--CommonLibs/Logger.h8
2 files changed, 17 insertions, 93 deletions
diff --git a/CommonLibs/Logger.cpp b/CommonLibs/Logger.cpp
index d246584..1c462e7 100644
--- a/CommonLibs/Logger.cpp
+++ b/CommonLibs/Logger.cpp
@@ -50,7 +50,8 @@ Mutex gLogToLock;
// Reference to a global config table, used all over the system.
extern ConfigurationTable gConfig;
-
+// Global log level threshold:
+int config_log_level;
/**@ The global alarms table. */
//@{
@@ -97,22 +98,6 @@ int levelStringToInt(const string& name)
return -1;
}
-/** Given a string, return the corresponding level name. */
-int lookupLevel(const string& key)
-{
- string val = gConfig.getStr(key);
- int level = levelStringToInt(val);
-
- if (level == -1) {
- string defaultLevel = gConfig.mSchema["Log.Level"].getDefaultValue();
- level = levelStringToInt(defaultLevel);
- _LOG(CRIT) << "undefined logging level (" << key << " = \"" << val << "\") defaulting to \"" << defaultLevel << ".\" Valid levels are: EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO or DEBUG";
- gConfig.set(key, defaultLevel);
- }
-
- return level;
-}
-
static std::string format(const char *fmt, ...)
{
va_list ap;
@@ -139,62 +124,6 @@ std::ostream& operator<<(std::ostream& os, std::ostringstream& ss)
return os << ss.str();
}
-int getLoggingLevel(const char* filename)
-{
- // Default level?
- if (!filename) return lookupLevel("Log.Level");
-
- // This can afford to be inefficient since it is not called that often.
- const string keyName = string("Log.Level.") + string(filename);
- if (gConfig.defines(keyName)) return lookupLevel(keyName);
- return lookupLevel("Log.Level");
-}
-
-
-
-int gGetLoggingLevel(const char* filename)
-{
- // This is called a lot and needs to be efficient.
-
- static Mutex sLogCacheLock;
- static map<uint64_t,int> sLogCache;
- static unsigned sCacheCount;
- static const unsigned sCacheRefreshCount = 1000;
-
- if (filename==NULL) return gGetLoggingLevel("");
-
- HashString hs(filename);
- uint64_t key = hs.hash();
-
- sLogCacheLock.lock();
- // Time for a cache flush?
- if (sCacheCount>sCacheRefreshCount) {
- sLogCache.clear();
- sCacheCount=0;
- }
- // Is it cached already?
- map<uint64_t,int>::const_iterator where = sLogCache.find(key);
- sCacheCount++;
- if (where!=sLogCache.end()) {
- int retVal = where->second;
- sLogCacheLock.unlock();
- return retVal;
- }
- // Look it up in the config table and cache it.
- // FIXME: Figure out why unlock and lock below fix the config table deadlock.
- // (pat) Probably because getLoggingLevel may call LOG recursively via lookupLevel().
- sLogCacheLock.unlock();
- int level = getLoggingLevel(filename);
- sLogCacheLock.lock();
- sLogCache.insert(pair<uint64_t,int>(key,level));
- sLogCacheLock.unlock();
- return level;
-}
-
-
-
-
-
// copies the alarm list and returns it. list supposed to be small.
list<string> gGetLoggerAlarms()
{
@@ -268,26 +197,21 @@ ostringstream& Log::get()
-void gLogInit(const char* name, const char* level, int facility)
+void gLogInit(const char* name, const char* level, int facility, char* fn)
{
// Set the level if one has been specified.
- if (level) {
- gConfig.set("Log.Level",level);
- }
+ if (level)
+ config_log_level = levelStringToInt(level);
// Both the transceiver and OpenBTS use this same facility, but only OpenBTS/OpenNodeB may use this log file:
- string str = gConfig.getStr("Log.File");
- if (gLogToFile==NULL && str.length() && 0==strncmp(gCmdName,"Open",4)) {
- const char *fn = str.c_str();
- if (fn && *fn && strlen(fn)>3) { // strlen because a garbage char is getting in sometimes.
- gLogToFile = fopen(fn,"w"); // New log file each time we start.
- if (gLogToFile) {
- time_t now;
- time(&now);
- fprintf(gLogToFile,"Starting at %s",ctime(&now));
- fflush(gLogToFile);
- std::cout << "Logging to file: " << fn << "\n";
- }
+ if (!gLogToFile && fn) {
+ gLogToFile = fopen(fn,"w"); // New log file each time we start.
+ if (gLogToFile) {
+ time_t now;
+ time(&now);
+ fprintf(gLogToFile,"Starting at %s",ctime(&now));
+ fflush(gLogToFile);
+ std::cout << "Logging to file: " << fn << "\n";
}
}
diff --git a/CommonLibs/Logger.h b/CommonLibs/Logger.h
index 68c5a9b..099d300 100644
--- a/CommonLibs/Logger.h
+++ b/CommonLibs/Logger.h
@@ -40,11 +40,13 @@
#include <map>
#include <string>
+extern int config_log_level;
+
#define _LOG(level) \
Log(LOG_##level).get() << pthread_self() \
<< timestr() << " " __FILE__ ":" << __LINE__ << ":" << __FUNCTION__ << ": "
-#define IS_LOG_LEVEL(wLevel) (gGetLoggingLevel(__FILE__)>=LOG_##wLevel)
+#define IS_LOG_LEVEL(wLevel) (config_log_level>=LOG_##wLevel)
#ifdef NDEBUG
#define LOG(wLevel) \
@@ -128,9 +130,7 @@ std::ostream& operator<<(std::ostream& os, std::ostringstream& ss);
/**@ Global control and initialization of the logging system. */
//@{
/** Initialize the global logging system. */
-void gLogInit(const char* name, const char* level=NULL, int facility=LOG_USER);
-/** Get the logging level associated with a given file. */
-int gGetLoggingLevel(const char *filename=NULL);
+void gLogInit(const char* name, const char* level=NULL, int facility=LOG_USER, char* fn=NULL);
/** Allow early logging when still in constructors */
void gLogEarly(int level, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
//@}