Logger: Drop syslog support
This feature is currently not being used, so let's drop it to make it easier to integrate into libosmocore logging system in the future. Change-Id: I8282745ef0282d41599eaf94fe460a1d29b18e2a
This commit is contained in:
parent
8bd111c942
commit
11d50d950c
|
@ -39,7 +39,6 @@ using namespace std;
|
||||||
|
|
||||||
// Switches to enable/disable logging targets
|
// Switches to enable/disable logging targets
|
||||||
bool gLogToConsole = true;
|
bool gLogToConsole = true;
|
||||||
bool gLogToSyslog = false;
|
|
||||||
FILE *gLogToFile = NULL;
|
FILE *gLogToFile = NULL;
|
||||||
Mutex gLogToLock;
|
Mutex gLogToLock;
|
||||||
|
|
||||||
|
@ -99,16 +98,10 @@ std::ostream& operator<<(std::ostream& os, std::ostringstream& ss)
|
||||||
|
|
||||||
Log::~Log()
|
Log::~Log()
|
||||||
{
|
{
|
||||||
if (mDummyInit) return;
|
|
||||||
// Anything at or above LOG_CRIT is an "alarm".
|
// Anything at or above LOG_CRIT is an "alarm".
|
||||||
if (mPriority <= LOG_ERR) {
|
if (mPriority <= LOG_ERR) {
|
||||||
cerr << mStream.str() << endl;
|
cerr << mStream.str() << endl;
|
||||||
}
|
}
|
||||||
// Current logging level was already checked by the macro. So just log.
|
|
||||||
// Log to syslog
|
|
||||||
if (gLogToSyslog) {
|
|
||||||
syslog(mPriority, "%s", mStream.str().c_str());
|
|
||||||
}
|
|
||||||
// Log to file and console
|
// Log to file and console
|
||||||
if (gLogToConsole||gLogToFile) {
|
if (gLogToConsole||gLogToFile) {
|
||||||
int mlen = mStream.str().size();
|
int mlen = mStream.str().size();
|
||||||
|
@ -128,14 +121,6 @@ Log::~Log()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Log::Log(const char* name, const char* level, int facility)
|
|
||||||
{
|
|
||||||
mDummyInit = true;
|
|
||||||
gLogInit(name, level, facility);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ostringstream& Log::get()
|
ostringstream& Log::get()
|
||||||
{
|
{
|
||||||
assert(mPriority<numLevels);
|
assert(mPriority<numLevels);
|
||||||
|
@ -145,7 +130,7 @@ ostringstream& Log::get()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void gLogInit(const char* name, const char* level, int facility, char* fn)
|
void gLogInit(const char* level, char *fn)
|
||||||
{
|
{
|
||||||
// Set the level if one has been specified.
|
// Set the level if one has been specified.
|
||||||
if (level)
|
if (level)
|
||||||
|
@ -162,9 +147,6 @@ void gLogInit(const char* name, const char* level, int facility, char* fn)
|
||||||
std::cout << "Logging to file: " << fn << "\n";
|
std::cout << "Logging to file: " << fn << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the log connection.
|
|
||||||
openlog(name,0,facility);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim: ts=4 sw=4
|
// vim: ts=4 sw=4
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
#ifndef LOGGER_H
|
#ifndef LOGGER_H
|
||||||
#define LOGGER_H
|
#define LOGGER_H
|
||||||
|
|
||||||
#include <syslog.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -42,6 +41,15 @@
|
||||||
|
|
||||||
extern int config_log_level;
|
extern int config_log_level;
|
||||||
|
|
||||||
|
#define LOG_EMERG 0 /* system is unusable */
|
||||||
|
#define LOG_ALERT 1 /* action must be taken immediately */
|
||||||
|
#define LOG_CRIT 2 /* critical conditions */
|
||||||
|
#define LOG_ERR 3 /* error conditions */
|
||||||
|
#define LOG_WARNING 4 /* warning conditions */
|
||||||
|
#define LOG_NOTICE 5 /* normal but significant condition */
|
||||||
|
#define LOG_INFO 6 /* informational */
|
||||||
|
#define LOG_DEBUG 7 /* debug-level messages */
|
||||||
|
|
||||||
#define _LOG(level) \
|
#define _LOG(level) \
|
||||||
Log(LOG_##level).get() << pthread_self() \
|
Log(LOG_##level).get() << pthread_self() \
|
||||||
<< timestr() << " " __FILE__ ":" << __LINE__ << ":" << __FUNCTION__ << ": "
|
<< timestr() << " " __FILE__ ":" << __LINE__ << ":" << __FUNCTION__ << ": "
|
||||||
|
@ -56,23 +64,10 @@ extern int config_log_level;
|
||||||
if (IS_LOG_LEVEL(wLevel)) _LOG(wLevel)
|
if (IS_LOG_LEVEL(wLevel)) _LOG(wLevel)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// pat: And for your edification here are the 'levels' as defined in syslog.h:
|
|
||||||
// LOG_EMERG 0 system is unusable
|
|
||||||
// LOG_ALERT 1 action must be taken immediately
|
|
||||||
// LOG_CRIT 2 critical conditions
|
|
||||||
// LOG_ERR 3 error conditions
|
|
||||||
// LOG_WARNING 4 warning conditions
|
|
||||||
// LOG_NOTICE 5 normal, but significant, condition
|
|
||||||
// LOG_INFO 6 informational message
|
|
||||||
// LOG_DEBUG 7 debug-level message
|
|
||||||
|
|
||||||
|
|
||||||
#include "Threads.h" // must be after defines above, if these files are to be allowed to use LOG()
|
#include "Threads.h" // must be after defines above, if these files are to be allowed to use LOG()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A C++ stream-based thread-safe logger.
|
A C++ stream-based thread-safe logger.
|
||||||
Derived from Dr. Dobb's Sept. 2007 issue.
|
|
||||||
Updated to use syslog.
|
|
||||||
This object is NOT the global logger;
|
This object is NOT the global logger;
|
||||||
every log record is an object of this class.
|
every log record is an object of this class.
|
||||||
*/
|
*/
|
||||||
|
@ -84,16 +79,13 @@ class Log {
|
||||||
|
|
||||||
std::ostringstream mStream; ///< This is where we buffer up the log entry.
|
std::ostringstream mStream; ///< This is where we buffer up the log entry.
|
||||||
int mPriority; ///< Priority of current report.
|
int mPriority; ///< Priority of current report.
|
||||||
bool mDummyInit;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Log(int wPriority)
|
Log(int wPriority)
|
||||||
:mPriority(wPriority), mDummyInit(false)
|
:mPriority(wPriority)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
Log(const char* name, const char* level=NULL, int facility=LOG_USER);
|
|
||||||
|
|
||||||
// Most of the work is in the destructor.
|
// Most of the work is in the destructor.
|
||||||
/** The destructor actually generates the log entry. */
|
/** The destructor actually generates the log entry. */
|
||||||
~Log();
|
~Log();
|
||||||
|
@ -101,7 +93,6 @@ class Log {
|
||||||
std::ostringstream& get();
|
std::ostringstream& get();
|
||||||
};
|
};
|
||||||
extern bool gLogToConsole; // Output log messages to stdout
|
extern bool gLogToConsole; // Output log messages to stdout
|
||||||
extern bool gLogToSyslog; // Output log messages to syslog
|
|
||||||
|
|
||||||
const std::string timestr(); // A timestamp to print in messages.
|
const std::string timestr(); // A timestamp to print in messages.
|
||||||
std::ostream& operator<<(std::ostream& os, std::ostringstream& ss);
|
std::ostream& operator<<(std::ostream& os, std::ostringstream& ss);
|
||||||
|
@ -109,7 +100,7 @@ std::ostream& operator<<(std::ostream& os, std::ostringstream& ss);
|
||||||
/**@ Global control and initialization of the logging system. */
|
/**@ Global control and initialization of the logging system. */
|
||||||
//@{
|
//@{
|
||||||
/** Initialize the global logging system. */
|
/** Initialize the global logging system. */
|
||||||
void gLogInit(const char* name, const char* level=NULL, int facility=LOG_USER, char* fn=NULL);
|
void gLogInit(const char* level=NULL, char* fn=NULL);
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,14 +12,8 @@ To run osmo-trx, the following should be installed:
|
||||||
libuhd (https://gnuradio.org).
|
libuhd (https://gnuradio.org).
|
||||||
This is part of the GNURadio installation.
|
This is part of the GNURadio installation.
|
||||||
|
|
||||||
|
|
||||||
osmo-trx logs to syslogd as facility LOG_LOCAL7. Please set your /etc/syslog.conf
|
|
||||||
accordingly.
|
|
||||||
|
|
||||||
|
|
||||||
For information on specific executables, see tests/README.tests and
|
For information on specific executables, see tests/README.tests and
|
||||||
apps/README.apps.
|
apps/README.apps.
|
||||||
|
|
||||||
See https://osmocom.org/projects/osmotrx/wiki/OsmoTRX for more
|
See https://osmocom.org/projects/osmotrx/wiki/OsmoTRX for more
|
||||||
information.
|
information.
|
||||||
|
|
||||||
|
|
|
@ -520,7 +520,7 @@ int main(int argc, char *argv[])
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gLogInit("transceiver", config.log_level.c_str(), LOG_LOCAL7);
|
gLogInit(config.log_level.c_str());
|
||||||
|
|
||||||
srandom(time(NULL));
|
srandom(time(NULL));
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
gLogInit("LogTest","NOTICE",LOG_LOCAL7);
|
gLogInit("NOTICE");
|
||||||
|
|
||||||
Log(LOG_EMERG).get() << " testing the logger.";
|
Log(LOG_EMERG).get() << " testing the logger.";
|
||||||
Log(LOG_ALERT).get() << " testing the logger.";
|
Log(LOG_ALERT).get() << " testing the logger.";
|
||||||
|
|
Loading…
Reference in New Issue