introducing new logger

This commit is contained in:
Erik Frojdh
2020-03-11 10:54:55 +01:00
parent 2acf64b09c
commit 4aeb8bf62e
5 changed files with 34 additions and 34 deletions

View File

@@ -52,7 +52,7 @@ void Detector::loadConfig(const std::string &fname) {
int shm_id = getShmId(); int shm_id = getShmId();
freeSharedMemory(); freeSharedMemory();
pimpl = sls::make_unique<DetectorImpl>(shm_id); pimpl = sls::make_unique<DetectorImpl>(shm_id);
FILE_LOG(logINFO) << "Loading configuration file: " << fname; LOG(logINFO) << "Loading configuration file: " << fname;
loadParameters(fname); loadParameters(fname);
} }
@@ -71,7 +71,7 @@ void Detector::loadParameters(const std::string &fname) {
if (current_line.find('#') != std::string::npos) { if (current_line.find('#') != std::string::npos) {
current_line.erase(current_line.find('#')); current_line.erase(current_line.find('#'));
} }
FILE_LOG(logDEBUG1) LOG(logDEBUG1)
<< "current_line after removing comments:\n\t" << current_line; << "current_line after removing comments:\n\t" << current_line;
if (current_line.length() > 1) { if (current_line.length() > 1) {
parser.Parse(current_line); parser.Parse(current_line);

View File

@@ -140,7 +140,7 @@ void DetectorImpl::initSharedMemory(bool verify) {
} else { } else {
multi_shm.OpenSharedMemory(); multi_shm.OpenSharedMemory();
if (verify && multi_shm()->shmversion != MULTI_SHMVERSION) { if (verify && multi_shm()->shmversion != MULTI_SHMVERSION) {
FILE_LOG(logERROR) << "Multi shared memory (" << multiId LOG(logERROR) << "Multi shared memory (" << multiId
<< ") version mismatch " << ") version mismatch "
"(expected 0x" "(expected 0x"
<< std::hex << MULTI_SHMVERSION << " but got 0x" << std::hex << MULTI_SHMVERSION << " but got 0x"
@@ -195,7 +195,7 @@ void DetectorImpl::updateUserdetails() {
bool DetectorImpl::isAcquireReady() { bool DetectorImpl::isAcquireReady() {
if (multi_shm()->acquiringFlag) { if (multi_shm()->acquiringFlag) {
FILE_LOG(logWARNING) LOG(logWARNING)
<< "Acquire has already started. " << "Acquire has already started. "
"If previous acquisition terminated unexpectedly, " "If previous acquisition terminated unexpectedly, "
"reset busy flag to restart.(sls_detector_put clearbusy)"; "reset busy flag to restart.(sls_detector_put clearbusy)";
@@ -237,7 +237,7 @@ void DetectorImpl::setVirtualDetectorServers(const int numdet, const int port) {
void DetectorImpl::setHostname(const std::vector<std::string> &name) { void DetectorImpl::setHostname(const std::vector<std::string> &name) {
// this check is there only to allow the previous detsizechan command // this check is there only to allow the previous detsizechan command
if (multi_shm()->numberOfDetectors != 0) { if (multi_shm()->numberOfDetectors != 0) {
FILE_LOG(logWARNING) LOG(logWARNING)
<< "There are already detector(s) in shared memory." << "There are already detector(s) in shared memory."
"Freeing Shared memory now."; "Freeing Shared memory now.";
bool initialChecks = multi_shm()->initialChecks; bool initialChecks = multi_shm()->initialChecks;
@@ -252,7 +252,7 @@ void DetectorImpl::setHostname(const std::vector<std::string> &name) {
} }
void DetectorImpl::addSlsDetector(const std::string &hostname) { void DetectorImpl::addSlsDetector(const std::string &hostname) {
FILE_LOG(logINFO) << "Adding detector " << hostname; LOG(logINFO) << "Adding detector " << hostname;
int port = DEFAULT_PORTNO; int port = DEFAULT_PORTNO;
std::string host = hostname; std::string host = hostname;
@@ -265,7 +265,7 @@ void DetectorImpl::addSlsDetector(const std::string &hostname) {
if (host != "localhost") { if (host != "localhost") {
for (auto &d : detectors) { for (auto &d : detectors) {
if (d->getHostname() == host) { if (d->getHostname() == host) {
FILE_LOG(logWARNING) LOG(logWARNING)
<< "Detector " << host << "Detector " << host
<< "already part of the multiDetector!" << std::endl << "already part of the multiDetector!" << std::endl
<< "Remove it before adding it back in a new position!"; << "Remove it before adding it back in a new position!";
@@ -292,7 +292,7 @@ void DetectorImpl::addSlsDetector(const std::string &hostname) {
} }
void DetectorImpl::updateDetectorSize() { void DetectorImpl::updateDetectorSize() {
FILE_LOG(logDEBUG) << "Updating Multi-Detector Size: " << size(); LOG(logDEBUG) << "Updating Multi-Detector Size: " << size();
const slsDetectorDefs::xy det_size = detectors[0]->getNumberOfChannels(); const slsDetectorDefs::xy det_size = detectors[0]->getNumberOfChannels();
@@ -312,7 +312,7 @@ void DetectorImpl::updateDetectorSize() {
multi_shm()->numberOfChannels.x = det_size.x * ndetx; multi_shm()->numberOfChannels.x = det_size.x * ndetx;
multi_shm()->numberOfChannels.y = det_size.y * ndety; multi_shm()->numberOfChannels.y = det_size.y * ndety;
FILE_LOG(logDEBUG) << "\n\tNumber of Detectors in X direction:" LOG(logDEBUG) << "\n\tNumber of Detectors in X direction:"
<< multi_shm()->numberOfDetector.x << multi_shm()->numberOfDetector.x
<< "\n\tNumber of Detectors in Y direction:" << "\n\tNumber of Detectors in Y direction:"
<< multi_shm()->numberOfDetector.y << multi_shm()->numberOfDetector.y
@@ -359,18 +359,18 @@ void DetectorImpl::setGapPixelsinReceiver(bool enable) {
int DetectorImpl::createReceivingDataSockets(const bool destroy) { int DetectorImpl::createReceivingDataSockets(const bool destroy) {
if (destroy) { if (destroy) {
FILE_LOG(logINFO) << "Going to destroy data sockets"; LOG(logINFO) << "Going to destroy data sockets";
// close socket // close socket
zmqSocket.clear(); zmqSocket.clear();
client_downstream = false; client_downstream = false;
FILE_LOG(logINFO) << "Destroyed Receiving Data Socket(s)"; LOG(logINFO) << "Destroyed Receiving Data Socket(s)";
return OK; return OK;
} }
if (client_downstream) { if (client_downstream) {
return OK; return OK;
} }
FILE_LOG(logINFO) << "Going to create data sockets"; LOG(logINFO) << "Going to create data sockets";
size_t numSockets = detectors.size(); size_t numSockets = detectors.size();
size_t numSocketsPerDetector = 1; size_t numSocketsPerDetector = 1;
@@ -394,10 +394,10 @@ int DetectorImpl::createReceivingDataSockets(const bool destroy) {
.str() .str()
.c_str(), .c_str(),
portnum)); portnum));
FILE_LOG(logINFO) << "Zmq Client[" << iSocket << "] at " LOG(logINFO) << "Zmq Client[" << iSocket << "] at "
<< zmqSocket.back()->GetZmqServerAddress(); << zmqSocket.back()->GetZmqServerAddress();
} catch (...) { } catch (...) {
FILE_LOG(logERROR) LOG(logERROR)
<< "Could not create Zmq socket on port " << portnum; << "Could not create Zmq socket on port " << portnum;
createReceivingDataSockets(true); createReceivingDataSockets(true);
return FAIL; return FAIL;
@@ -405,7 +405,7 @@ int DetectorImpl::createReceivingDataSockets(const bool destroy) {
} }
client_downstream = true; client_downstream = true;
FILE_LOG(logINFO) << "Receiving Data Socket(s) created"; LOG(logINFO) << "Receiving Data Socket(s) created";
return OK; return OK;
} }
@@ -432,7 +432,7 @@ void DetectorImpl::readFrameFromReceiver() {
} else { } else {
// to remember the list it connected to, to disconnect later // to remember the list it connected to, to disconnect later
connectList[i] = false; connectList[i] = false;
FILE_LOG(logERROR) << "Could not connect to socket " LOG(logERROR) << "Could not connect to socket "
<< zmqSocket[i]->GetZmqServerAddress(); << zmqSocket[i]->GetZmqServerAddress();
runningList[i] = false; runningList[i] = false;
} }
@@ -516,7 +516,7 @@ void DetectorImpl::readFrameFromReceiver() {
(doc["gappixels"].GetUint() == 0) ? false : true; (doc["gappixels"].GetUint() == 0) ? false : true;
quadEnable = quadEnable =
(doc["quad"].GetUint() == 0) ? false : true; (doc["quad"].GetUint() == 0) ? false : true;
FILE_LOG(logDEBUG1) LOG(logDEBUG1)
<< "One Time Header Info:" << "One Time Header Info:"
"\n\tsize: " "\n\tsize: "
<< size << "\n\tmultisize: " << multisize << size << "\n\tmultisize: " << multisize
@@ -540,7 +540,7 @@ void DetectorImpl::readFrameFromReceiver() {
coordY = (nY - 1) - coordY; coordY = (nY - 1) - coordY;
} }
flippedDataX = doc["flippedDataX"].GetUint(); flippedDataX = doc["flippedDataX"].GetUint();
FILE_LOG(logDEBUG1) LOG(logDEBUG1)
<< "Header Info:" << "Header Info:"
"\n\tcurrentFileName: " "\n\tcurrentFileName: "
<< currentFileName << "\n\tcurrentAcquisitionIndex: " << currentFileName << "\n\tcurrentAcquisitionIndex: "
@@ -564,7 +564,7 @@ void DetectorImpl::readFrameFromReceiver() {
if (multi_shm()->multiDetectorType == CHIPTESTBOARD) { if (multi_shm()->multiDetectorType == CHIPTESTBOARD) {
singledetrowoffset = size; singledetrowoffset = size;
} }
FILE_LOG(logDEBUG1) LOG(logDEBUG1)
<< "Multi Image Info:" << "Multi Image Info:"
"\n\txoffset: " "\n\txoffset: "
<< xoffset << "\n\tyoffset: " << yoffset << xoffset << "\n\tyoffset: " << yoffset
@@ -591,7 +591,7 @@ void DetectorImpl::readFrameFromReceiver() {
} }
} }
} }
FILE_LOG(logDEBUG)<< "Call Back Info:" LOG(logDEBUG)<< "Call Back Info:"
<< "\n\t nDetPixelsX: " << nDetPixelsX << "\n\t nDetPixelsX: " << nDetPixelsX
<< "\n\t nDetPixelsY: " << nDetPixelsY << "\n\t nDetPixelsY: " << nDetPixelsY
<< "\n\t databytes: " << multisize << "\n\t databytes: " << multisize
@@ -611,7 +611,7 @@ void DetectorImpl::readFrameFromReceiver() {
} }
int n = processImageWithGapPixels(multiframe, multigappixels, int n = processImageWithGapPixels(multiframe, multigappixels,
quadEnable); quadEnable);
FILE_LOG(logDEBUG) LOG(logDEBUG)
<< "Call Back Info Recalculated:" << "Call Back Info Recalculated:"
<< "\n\t nDetPixelsX: " << nDetPixelsX << "\n\t nDetPixelsX: " << nDetPixelsX
<< "\n\t nDetPixelsY: " << nDetPixelsY << "\n\t nDetPixelsY: " << nDetPixelsY
@@ -885,7 +885,7 @@ double DetectorImpl::setTotalProgress() {
throw RuntimeError("Invalid Total Number of frames (0)"); throw RuntimeError("Invalid Total Number of frames (0)");
} }
totalProgress = tot; totalProgress = tot;
FILE_LOG(logDEBUG1) << "Set total progress " << totalProgress << std::endl; LOG(logDEBUG1) << "Set total progress " << totalProgress << std::endl;
return totalProgress; return totalProgress;
} }
@@ -992,7 +992,7 @@ int DetectorImpl::acquire() {
sem_destroy(&sem_endRTAcquisition); sem_destroy(&sem_endRTAcquisition);
clock_gettime(CLOCK_REALTIME, &end); clock_gettime(CLOCK_REALTIME, &end);
FILE_LOG(logDEBUG1) << "Elapsed time for acquisition:" LOG(logDEBUG1) << "Elapsed time for acquisition:"
<< ((end.tv_sec - begin.tv_sec) + << ((end.tv_sec - begin.tv_sec) +
(end.tv_nsec - begin.tv_nsec) / 1000000000.0) (end.tv_nsec - begin.tv_nsec) / 1000000000.0)
<< " seconds"; << " seconds";
@@ -1021,7 +1021,7 @@ void DetectorImpl::processData() {
// to exit acquire by typing q // to exit acquire by typing q
if (kbhit() != 0) { if (kbhit() != 0) {
if (fgetc(stdin) == 'q') { if (fgetc(stdin) == 'q') {
FILE_LOG(logINFO) LOG(logINFO)
<< "Caught the command to stop acquisition"; << "Caught the command to stop acquisition";
Parallel(&slsDetector::stopAcquisition, {}); Parallel(&slsDetector::stopAcquisition, {});
} }
@@ -1088,9 +1088,9 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
throw RuntimeError("programfpga not implemented for this detector"); throw RuntimeError("programfpga not implemented for this detector");
} }
FILE_LOG(logINFO) LOG(logINFO)
<< "Updating Firmware. This can take awhile. Please be patient..."; << "Updating Firmware. This can take awhile. Please be patient...";
FILE_LOG(logDEBUG1) << "Programming FPGA with file name:" << fname; LOG(logDEBUG1) << "Programming FPGA with file name:" << fname;
size_t filesize = 0; size_t filesize = 0;
// check if it exists // check if it exists
@@ -1119,7 +1119,7 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
} }
// convert src to dst rawbin // convert src to dst rawbin
FILE_LOG(logDEBUG1) << "Converting " << fname << " to " << destfname; LOG(logDEBUG1) << "Converting " << fname << " to " << destfname;
{ {
constexpr int pofNumHeaderBytes = 0x11C; constexpr int pofNumHeaderBytes = 0x11C;
constexpr int pofFooterOfst = 0x1000000; constexpr int pofFooterOfst = 0x1000000;
@@ -1168,7 +1168,7 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
if (close(dst) != 0) { if (close(dst) != 0) {
throw RuntimeError("Program FPGA: Could not close destination file"); throw RuntimeError("Program FPGA: Could not close destination file");
} }
FILE_LOG(logDEBUG1) << "File has been converted to " << destfname; LOG(logDEBUG1) << "File has been converted to " << destfname;
// loading dst file to memory // loading dst file to memory
FILE *fp = fopen(destfname, "r"); FILE *fp = fopen(destfname, "r");
@@ -1194,8 +1194,8 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
"Program FPGA: Could not close destination file after converting"); "Program FPGA: Could not close destination file after converting");
} }
unlink(destfname); // delete temporary file unlink(destfname); // delete temporary file
FILE_LOG(logDEBUG1) LOG(logDEBUG1)
<< "Successfully loaded the rawbin file to program memory"; << "Successfully loaded the rawbin file to program memory";
FILE_LOG(logINFO) << "Read file into memory"; LOG(logINFO) << "Read file into memory";
return buffer; return buffer;
} }

View File

@@ -188,3 +188,5 @@ inline void Output2FILE::Output(const std::string& msg, TLogLevel level)
} }
fflush(out ? stdout : pStream); fflush(out ? stdout : pStream);
} }
#include "logger2.h"

View File

@@ -2,7 +2,7 @@
/*Utility to log to console*/ /*Utility to log to console*/
#include "ansi.h" //Colors #include "ansi.h" //Colors
#include "logger.h" //for enum, to be removed // #include "logger.h" //for enum, to be removed
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
@@ -56,7 +56,7 @@ class Logger {
constexpr size_t buffer_len = 12; constexpr size_t buffer_len = 12;
char buffer[buffer_len]; char buffer[buffer_len];
time_t t; time_t t;
time(&t); ::time(&t);
tm r; tm r;
strftime(buffer, buffer_len, "%X", localtime_r(&t, &r)); strftime(buffer, buffer_len, "%X", localtime_r(&t, &r));
buffer[buffer_len - 1] = '\0'; buffer[buffer_len - 1] = '\0';

View File

@@ -1,7 +1,5 @@
#include "catch.hpp" #include "catch.hpp"
#include "logger.h" #include "logger.h"
#include "logger2.h"
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <chrono> #include <chrono>