mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-06 10:00:40 +02:00
working logger!
This commit is contained in:
parent
811bac16ec
commit
dc04efbbb1
@ -12,17 +12,25 @@ CFLAGS= -g -DC_ONLY -fPIC
|
||||
DFLAGS= -g -DDACS_INT -DSLS_RECEIVER_UDP_FUNCTIONS
|
||||
|
||||
INCLUDES?= -I. -Iincludes -IMySocketTCP -IslsReceiver -IslsDetectorCalibration -I$(ASM)
|
||||
|
||||
#-IslsReceiverInterface
|
||||
|
||||
SRC_CLNT= MySocketTCP/MySocketTCP.cpp slsReceiver/UDPInterface.cpp slsReceiver/UDPBaseImplementation.cpp slsReceiver/UDPStandardImplementation.cpp slsReceiver/UDPRESTImplementation.cpp slsReceiver/slsReceiverTCPIPInterface.cpp slsReceiver/slsReceiver.cpp slsReceiver/slsReceiverUsers.cpp includes/utilities.h
|
||||
SRC_CLNT = MySocketTCP/MySocketTCP.cpp slsReceiver/UDPInterface.cpp slsReceiver/UDPBaseImplementation.cpp slsReceiver/UDPStandardImplementation.cpp slsReceiver/slsReceiverTCPIPInterface.cpp slsReceiver/slsReceiver.cpp slsReceiver/slsReceiverUsers.cpp slsReceiver/utilities.cpp
|
||||
#slsReceiverInterface/receiverInterface.cpp
|
||||
#slsReceiver/slsReceiverUDPFunctions.cpp
|
||||
#slsReceiver/utilities.cpp includes/logger.h
|
||||
#ifeq ($(REST),yes)
|
||||
# SRC_CLNT += slsReceiver/UDPRESTImplementation.cpp
|
||||
# INCLUDES += $(RESTINCLUDE)
|
||||
#endif
|
||||
|
||||
OBJS = $(SRC_CLNT:.cpp=.o)
|
||||
OBJS += includes/utilities.h
|
||||
OBJS=$(SRC_CLNT:.cpp=.o)
|
||||
#OBJS = $(OBJS1:.h=.o)
|
||||
#OBJS += slsReceiver/logger.o
|
||||
#OBJS += slsReceiver/eigerReceiver.o
|
||||
|
||||
|
||||
|
||||
.PHONY: all intdoc package eigerReceiver clean
|
||||
|
||||
all: package $(SRC_CLNT)
|
||||
@ -30,19 +38,23 @@ all: package $(SRC_CLNT)
|
||||
intdoc: $(SRC_H) $(SRC_CLNT)
|
||||
doxygen doxy.config
|
||||
|
||||
|
||||
%.o : %.cpp Makefile
|
||||
ifeq ($(ROOTSLS),yes)
|
||||
echo "with root"
|
||||
$(CXX) -DROOTSLS -o $@ -c $< $(INCLUDES) $(DFLAGS) $(ROOTFLAGS) -fPIC $(EPICSFLAGS) -L/usr/lib64/ #$(FLAGS)
|
||||
else
|
||||
echo "without root"
|
||||
echo $(REST)
|
||||
echo $(INCLUDES)
|
||||
$(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread #$(FLAGS)
|
||||
endif
|
||||
|
||||
# LEO: not satisfied by eigerReceiver
|
||||
package: $(OBJS) $(DESTDIR)/libSlsReceiver.so $(DESTDIR)/libSlsReceiver.a
|
||||
|
||||
#slsReceiver/logger.o:
|
||||
# $(CXX) -o $@ -c includes/logger.h $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread #$(FLAGS)
|
||||
|
||||
#eigerReceiver:
|
||||
# echo "src client:" $(SRC_CLNT)
|
||||
# cd slsReceiver && make eigerReceiver
|
||||
@ -57,6 +69,7 @@ $(DESTDIR)/libSlsReceiver.a: $(OBJS)
|
||||
mv libSlsReceiver.a $(DESTDIR)
|
||||
|
||||
clean:
|
||||
echo rm -rf $(OBJS)
|
||||
rm -rf $(OBJS)
|
||||
cd slsReceiver && make clean
|
||||
cd
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef __LOG_H__
|
||||
#define __LOG_H__
|
||||
//#ifndef __LOG_H__
|
||||
//#define __LOG_H__
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@ -9,13 +9,11 @@ inline std::string NowTime();
|
||||
|
||||
enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4};
|
||||
|
||||
template <typename T>
|
||||
class Log{
|
||||
template <typename T> class Log{
|
||||
public:
|
||||
Log();
|
||||
virtual ~Log();
|
||||
std::ostringstream& Get(TLogLevel level = logINFO);
|
||||
public:
|
||||
static TLogLevel& ReportingLevel();
|
||||
static std::string ToString(TLogLevel level);
|
||||
static TLogLevel FromString(const std::string& level);
|
||||
@ -26,55 +24,6 @@ class Log{
|
||||
Log& operator =(const Log&);
|
||||
};
|
||||
|
||||
template <typename T> Log<T>::Log() {}
|
||||
|
||||
template <typename T> std::ostringstream& Log<T>::Get(TLogLevel level)
|
||||
{
|
||||
os << "- " << NowTime();
|
||||
os << " " << ToString(level) << ": ";
|
||||
os << std::string(level > logDEBUG ? level - logDEBUG : 0, '\t');
|
||||
return os;
|
||||
}
|
||||
|
||||
template <typename T> Log<T>::~Log()
|
||||
{
|
||||
os << std::endl;
|
||||
T::Output(os.str());
|
||||
}
|
||||
|
||||
template <typename T> TLogLevel& Log<T>::ReportingLevel()
|
||||
{
|
||||
static TLogLevel reportingLevel = logDEBUG4;
|
||||
return reportingLevel;
|
||||
}
|
||||
|
||||
template <typename T> std::string Log<T>::ToString(TLogLevel level)
|
||||
{
|
||||
static const char* const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4"};
|
||||
return buffer[level];
|
||||
}
|
||||
|
||||
template <typename T> TLogLevel Log<T>::FromString(const std::string& level)
|
||||
{
|
||||
if (level == "DEBUG4")
|
||||
return logDEBUG4;
|
||||
if (level == "DEBUG3")
|
||||
return logDEBUG3;
|
||||
if (level == "DEBUG2")
|
||||
return logDEBUG2;
|
||||
if (level == "DEBUG1")
|
||||
return logDEBUG1;
|
||||
if (level == "DEBUG")
|
||||
return logDEBUG;
|
||||
if (level == "INFO")
|
||||
return logINFO;
|
||||
if (level == "WARNING")
|
||||
return logWARNING;
|
||||
if (level == "ERROR")
|
||||
return logERROR;
|
||||
Log<T>().Get(logWARNING) << "Unknown logging level '" << level << "'. Using INFO level as default.";
|
||||
return logINFO;
|
||||
}
|
||||
|
||||
class Output2FILE {
|
||||
public:
|
||||
@ -82,20 +31,6 @@ public:
|
||||
static void Output(const std::string& msg);
|
||||
};
|
||||
|
||||
inline FILE*& Output2FILE::Stream() {
|
||||
static FILE* pStream = stderr;
|
||||
return pStream;
|
||||
}
|
||||
|
||||
inline void Output2FILE::Output(const std::string& msg)
|
||||
{
|
||||
FILE* pStream = Stream();
|
||||
if (!pStream)
|
||||
return;
|
||||
fprintf(pStream, "%s", msg.c_str());
|
||||
fflush(pStream);
|
||||
}
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||
# if defined (BUILDING_FILELOG_DLL)
|
||||
# define FILELOG_DECLSPEC __declspec (dllexport)
|
||||
@ -124,6 +59,8 @@ class FILELOG_DECLSPEC FILELog : public Log<Output2FILE> {};
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
|
||||
inline std::string NowTime()
|
||||
|
||||
{
|
||||
@ -159,4 +96,86 @@ inline std::string NowTime()
|
||||
|
||||
#endif //WIN32
|
||||
|
||||
#endif //__LOG_H__
|
||||
|
||||
template <typename T> Log<T>::Log(){}
|
||||
|
||||
template <typename T> std::ostringstream& Log<T>::Get(TLogLevel level)
|
||||
{
|
||||
os << "- " << NowTime();
|
||||
os << " " << ToString(level) << ": ";
|
||||
os << std::string(level > logDEBUG ? level - logDEBUG : 0, '\t');
|
||||
return os;
|
||||
}
|
||||
|
||||
template <typename T> Log<T>::~Log()
|
||||
{
|
||||
os << std::endl;
|
||||
T::Output(os.str());
|
||||
}
|
||||
|
||||
template <typename T> TLogLevel& Log<T>::ReportingLevel()
|
||||
{
|
||||
static TLogLevel reportingLevel = logDEBUG4;
|
||||
return reportingLevel;
|
||||
}
|
||||
|
||||
template <typename T> std::string Log<T>::ToString(TLogLevel level)
|
||||
{
|
||||
static const char* const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4"};
|
||||
return buffer[level];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
TLogLevel Log<T>::FromString(const std::string& level)
|
||||
{
|
||||
if (level == "DEBUG4")
|
||||
return logDEBUG4;
|
||||
if (level == "DEBUG3")
|
||||
return logDEBUG3;
|
||||
if (level == "DEBUG2")
|
||||
return logDEBUG2;
|
||||
if (level == "DEBUG1")
|
||||
return logDEBUG1;
|
||||
if (level == "DEBUG")
|
||||
return logDEBUG;
|
||||
if (level == "INFO")
|
||||
return logINFO;
|
||||
if (level == "WARNING")
|
||||
return logWARNING;
|
||||
if (level == "ERROR")
|
||||
return logERROR;
|
||||
Log<T>().Get(logWARNING) << "Unknown logging level '" << level << "'. Using INFO level as default.";
|
||||
return logINFO;
|
||||
}
|
||||
|
||||
|
||||
inline FILE*& Output2FILE::Stream()
|
||||
{
|
||||
static FILE* pStream = stderr;
|
||||
return pStream;
|
||||
}
|
||||
|
||||
inline void Output2FILE::Output(const std::string& msg)
|
||||
{
|
||||
FILE* pStream = Stream();
|
||||
if (!pStream)
|
||||
return;
|
||||
fprintf(pStream, "%s", msg.c_str());
|
||||
fflush(pStream);
|
||||
}
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||
# if defined (BUILDING_FILELOG_DLL)
|
||||
# define FILELOG_DECLSPEC __declspec (dllexport)
|
||||
# elif defined (USING_FILELOG_DLL)
|
||||
# define FILELOG_DECLSPEC __declspec (dllimport)
|
||||
# else
|
||||
# define FILELOG_DECLSPEC
|
||||
# endif // BUILDING_DBSIMPLE_DLL
|
||||
#else
|
||||
# define FILELOG_DECLSPEC
|
||||
#endif // _WIN32
|
||||
|
||||
|
||||
|
||||
//#endif //__LOG_H__
|
||||
|
@ -3,27 +3,11 @@
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#include "sls_receiver_defs.h"
|
||||
|
||||
/* uncomment next line to enable debug output */
|
||||
//#define EIGER_DEBUG
|
||||
|
||||
/* macro for debug output http://stackoverflow.com/a/14256296 */
|
||||
#ifdef EIGER_DEBUG
|
||||
#define DEBUG(x) do { std::cerr << x << std::endl; } while (0)
|
||||
#else
|
||||
#define DEBUG(x)
|
||||
#endif
|
||||
|
||||
#ifdef VERBOSE
|
||||
#define VERBOSE_PRINT(x) do { std::cout << "[VERBOSE]" << x << std::endl; } while (0)
|
||||
#else
|
||||
#define VERBOSE_PRINT(x)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
inline int read_config_file(string fname, int *tcpip_port_no);
|
||||
int read_config_file(string fname, int *tcpip_port_no);
|
||||
|
||||
|
@ -34,8 +34,11 @@ UDPInterface * UDPInterface::create(string receiver_type){
|
||||
cout << "Starting " << receiver_type << endl;
|
||||
return new UDPStandardImplementation();
|
||||
}
|
||||
//else if (receiver_type == "REST")
|
||||
// return new UDPRESTImplementation();
|
||||
|
||||
#ifdef REST
|
||||
else if (receiver_type == "REST")
|
||||
return new UDPRESTImplementation();
|
||||
#endif
|
||||
else{
|
||||
FILE_LOG(logWARNING) << "[ERROR] UDP interface not supported, using standard implementation";
|
||||
return new UDPBaseImplementation();
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include "MySocketTCP.h"
|
||||
|
||||
#include "utilities.h"
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
/*
|
||||
void print_not_implemented(string method_name){
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "utilities.h"
|
||||
#include "logger.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
66
slsReceiverSoftware/slsReceiver/utilities.cpp
Normal file
66
slsReceiverSoftware/slsReceiver/utilities.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <fstream>
|
||||
|
||||
#include "utilities.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int read_config_file(string fname, int *tcpip_port_no){
|
||||
|
||||
ifstream infile;
|
||||
string sLine,sargname;
|
||||
int iline = 0;
|
||||
int success = slsReceiverDefs::OK;
|
||||
|
||||
infile.open(fname.c_str(), ios_base::in);
|
||||
if (infile.is_open()) {
|
||||
while(infile.good()){
|
||||
getline(infile,sLine);
|
||||
iline++;
|
||||
|
||||
//VERBOSE_PRINT(sLine);
|
||||
|
||||
if(sLine.find('#')!=string::npos){
|
||||
//VERBOSE_PRINT( "Line is a comment ");
|
||||
continue;
|
||||
}
|
||||
else if(sLine.length()<2){
|
||||
//VERBOSE_PRINT("Empty line ");
|
||||
continue;
|
||||
}
|
||||
else{
|
||||
istringstream sstr(sLine);
|
||||
|
||||
//parameter name
|
||||
if(sstr.good())
|
||||
sstr >> sargname;
|
||||
|
||||
//tcp port
|
||||
if(sargname=="rx_tcpport"){
|
||||
if(sstr.good()) {
|
||||
sstr >> sargname;
|
||||
if(sscanf(sargname.c_str(),"%d",tcpip_port_no))
|
||||
cout<<"dataport:"<<tcpip_port_no<<endl;
|
||||
else{
|
||||
cout << "could not decode port in config file. Exiting." << endl;
|
||||
success = slsReceiverDefs::FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user