aboutsummaryrefslogtreecommitdiffstats
path: root/CommonLibs/Logger.cpp
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2018-02-20 20:01:10 +0100
committerHarald Welte <laforge@gnumonks.org>2018-02-27 07:11:11 +0000
commit3da1f8352e337fb032bf7a58c2909d3ba918e237 (patch)
tree33efd20443a363cd783da4dea99255210237097e /CommonLibs/Logger.cpp
parent5ea1817dc299611808532eda489981f09f87cba3 (diff)
Logger: Use libosmocore logging system
We still need an intermediate class Logger due to osmo-trx being multi-threaded and requiring to have a lock to use libosmocore, which is not thread safe. Change-Id: I30baac89f53e927f8699d0586b43cccf88ecd493
Diffstat (limited to 'CommonLibs/Logger.cpp')
-rw-r--r--CommonLibs/Logger.cpp73
1 files changed, 3 insertions, 70 deletions
diff --git a/CommonLibs/Logger.cpp b/CommonLibs/Logger.cpp
index 4c2a2d3..ac3de42 100644
--- a/CommonLibs/Logger.cpp
+++ b/CommonLibs/Logger.cpp
@@ -1,7 +1,5 @@
/*
-* Copyright 2009, 2010 Free Software Foundation, Inc.
-* Copyright 2010 Kestrel Signal Processing, Inc.
-* Copyright 2011, 2012 Range Networks, Inc.
+* Copyright (C) 2018 sysmocom - s.f.m.c. GmbH
*
*
* This software is distributed under the terms of the GNU Affero Public License.
@@ -39,55 +37,6 @@ using namespace std;
Mutex gLogToLock;
-// Global log level threshold:
-int config_log_level;
-
-/** Names of the logging levels. */
-const char *levelNames[] = {
- "EMERG", "ALERT", "CRIT", "ERR", "WARNING", "NOTICE", "INFO", "DEBUG"
-};
-int numLevels = 8;
-
-
-int levelStringToInt(const string& name)
-{
- // Reverse search, since the numerically larger levels are more common.
- for (int i=numLevels-1; i>=0; i--) {
- if (name == levelNames[i]) return i;
- }
-
- // Common substitutions.
- if (name=="INFORMATION") return 6;
- if (name=="WARN") return 4;
- if (name=="ERROR") return 3;
- if (name=="CRITICAL") return 2;
- if (name=="EMERGENCY") return 0;
-
- // Unknown level.
- return -1;
-}
-
-static std::string format(const char *fmt, ...)
-{
- va_list ap;
- char buf[300];
- va_start(ap,fmt);
- int n = vsnprintf(buf,300,fmt,ap);
- va_end(ap);
- if (n >= (300-4)) { strcpy(&buf[(300-4)],"..."); }
- return std::string(buf);
-}
-
-const std::string timestr()
-{
- struct timeval tv;
- struct tm tm;
- gettimeofday(&tv,NULL);
- localtime_r(&tv.tv_sec,&tm);
- unsigned tenths = tv.tv_usec / 100000; // Rounding down is ok.
- return format(" %02d:%02d:%02d.%1d",tm.tm_hour,tm.tm_min,tm.tm_sec,tenths);
-}
-
std::ostream& operator<<(std::ostream& os, std::ostringstream& ss)
{
return os << ss.str();
@@ -95,34 +44,18 @@ std::ostream& operator<<(std::ostream& os, std::ostringstream& ss)
Log::~Log()
{
- // Anything at or above LOG_CRIT is an "alarm".
- if (mPriority <= LOG_ERR) {
- cerr << mStream.str() << endl;
- }
-
int mlen = mStream.str().size();
int neednl = (mlen==0 || mStream.str()[mlen-1] != '\n');
+ const char *fmt = neednl ? "%s\n" : "%s";
ScopedLock lock(gLogToLock);
// The COUT() macro prevents messages from stomping each other but adds uninteresting thread numbers,
// so just use std::cout.
- std::cout << mStream.str();
- if (neednl) std::cout<<"\n";
+ LOGP(mCategory, mPriority, fmt, mStream.str().c_str());
}
ostringstream& Log::get()
{
- assert(mPriority<numLevels);
- mStream << levelNames[mPriority] << ' ';
return mStream;
}
-
-
-void gLogInit(const char* level, char *fn)
-{
- // Set the level if one has been specified.
- if (level)
- config_log_level = levelStringToInt(level);
-}
-
// vim: ts=4 sw=4