Skip to content

Commit

Permalink
jout and jerr use JLogger instead of JStreamLog
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwbrei committed Dec 13, 2024
1 parent 1f9d73b commit 1cd40ad
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 47 deletions.
1 change: 1 addition & 0 deletions src/libraries/JANA/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(JANA2_SOURCES
JService.cc
JVersion.cc
JEvent.cc
JLogger.cc

Engine/JExecutionEngine.cc

Expand Down
11 changes: 5 additions & 6 deletions src/libraries/JANA/Calibrations/JCalibration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
// Subject to the terms in the LICENSE file found in the top-level directory.

#include <JANA/JLogger.h>
#include <JANA/Compatibility/JStreamLog.h>
#include "JCalibration.h"

#include <unistd.h>
#include <errno.h>
#include <cstring>
#include <dirent.h>

#include <fstream>
#include <iostream>
#include <string>
#include <fstream>
#include <sys/stat.h>
#include <unistd.h>

using namespace std;

#include <sys/stat.h>


//---------------------------------
Expand Down
1 change: 0 additions & 1 deletion src/libraries/JANA/Calibrations/JCalibrationFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Subject to the terms in the LICENSE file found in the top-level directory.

#include "JCalibrationFile.h"
#include <JANA/Compatibility/JStreamLog.h>
#include <JANA/JLogger.h>

#include <dirent.h>
Expand Down
9 changes: 5 additions & 4 deletions src/libraries/JANA/Calibrations/JLargeCalibration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
// Creator: davidl (on Darwin eleanor.jlab.org 12.2.0 i386)
//

#include <JANA/JLogger.h>
#include <JANA/Services/JParameterManager.h>
#include <JANA/Calibrations/JLargeCalibration.h>

#include <md5.h>

#include <JANA/Compatibility/JStreamLog.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
Expand All @@ -20,9 +24,6 @@ using namespace std;
#include <curl/curl.h>
#endif // HAVE_CURL

#include <JANA/Services/JParameterManager.h>
#include <JANA/Calibrations/JLargeCalibration.h>
#include <md5.h>


static pthread_mutex_t resource_manager_mutex = PTHREAD_MUTEX_INITIALIZER;
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/JANA/Compatibility/JGeometryXML.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#pragma once
#include <iostream>

#include <JANA/JLogger.h>
#include <JANA/Compatibility/JGeometry.h>
#include <JANA/Compatibility/JStreamLog.h>
#include <JANA/Calibrations/JCalibration.h>
#include <JANA/JVersion.h>

Expand Down
3 changes: 0 additions & 3 deletions src/libraries/JANA/Compatibility/JStreamLog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

#include "JStreamLog.h"

JStreamLog jout(std::cout, "JANA >>");
JStreamLog jerr(std::cerr, "JANA ERROR>>");

JStreamLog::JStreamLog(std::streambuf* buf, const char* tag) : std::ostream(new JStreamLogBuffer(buf, tag)), own_rdbuf(true)
{}

Expand Down
5 changes: 0 additions & 5 deletions src/libraries/JANA/Compatibility/JStreamLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ class JStreamLog : public std::ostream

std::ostream& endMsg(std::ostream& os);

extern JStreamLog jout;
extern JStreamLog jerr;
#define jendl std::endl

#define _DBG_ std::cerr<<__FILE__<<":"<<__LINE__<<" "
#define _DBG__ std::cerr<<__FILE__<<":"<<__LINE__<<std::endl


7 changes: 7 additions & 0 deletions src/libraries/JANA/JLogger.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#include <JANA/JLogger.h>

JLogger jout {JLogger::Level::INFO, &std::cout, "jana"};
JLogger jerr {JLogger::Level::ERROR, &std::cerr, "jana"};


15 changes: 10 additions & 5 deletions src/libraries/JANA/JLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#pragma once

#include <JANA/Compatibility/JStreamLog.h>

#include <iostream>
#include <sstream>
#include <chrono>
Expand Down Expand Up @@ -41,9 +39,6 @@ struct JLogger {
};


static JLogger default_cout_logger = JLogger(JLogger::Level::TRACE, &std::cout, "JANA");
static JLogger default_cerr_logger = JLogger(JLogger::Level::TRACE, &std::cerr, "JERR");


inline std::ostream& operator<<(std::ostream& s, JLogger::Level l) {
switch (l) {
Expand Down Expand Up @@ -147,3 +142,13 @@ JLogMessage operator<<(const JLogger& logger, T&& t) {
#define LOG_TRACE(logger) LOG_AT_LEVEL(logger, JLogger::Level::TRACE)


/// Backwards compatibility with JANA1 logger

extern JLogger jout;
extern JLogger jerr;
#define jendl std::endl
#define default_cout_logger jout;
#define default_cerr_logger jerr;
#define _DBG_ jerr<<__FILE__<<":"<<__LINE__<<" "
#define _DBG__ jerr<<__FILE__<<":"<<__LINE__<<std::endl

29 changes: 13 additions & 16 deletions src/libraries/JANA/Utils/JCallGraphRecorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
// Created by Nathan Brei on 10/25/21.
//



#include "JCallGraphRecorder.h"

#include <sstream>
#include <JANA/Compatibility/JStreamLog.h>
#include <queue>
#include <JANA/JLogger.h>

#include <algorithm>
#include <map>
#include <queue>
#include <sstream>

using std::vector;
using std::string;
using std::endl;

void JCallGraphRecorder::Reset() {
m_call_graph.clear();
Expand All @@ -24,10 +21,10 @@ void JCallGraphRecorder::Reset() {
void JCallGraphRecorder::PrintErrorCallStack() const {

// Create a list of the call strings while finding the longest one
vector<string> routines;
std::vector<std::string> routines;
unsigned int max_length = 0;
for(unsigned int i=0; i<m_error_call_stack.size(); i++){
string routine = m_error_call_stack[i].factory_name;
std::string routine = m_error_call_stack[i].factory_name;
if(m_error_call_stack[i].tag.length()){
routine = routine + ":" + m_error_call_stack[i].tag;
}
Expand All @@ -36,17 +33,17 @@ void JCallGraphRecorder::PrintErrorCallStack() const {
}

std::stringstream sstr;
sstr<<" Factory Call Stack"<<endl;
sstr<<"============================"<<endl;
sstr<<" Factory Call Stack"<<std::endl;
sstr<<"============================"<<std::endl;
for(unsigned int i=0; i<m_error_call_stack.size(); i++){
string routine = routines[i];
sstr<<" "<<routine<<string(max_length+2 - routine.size(),' ');
std::string routine = routines[i];
sstr<<" "<<routine<<std::string(max_length+2 - routine.size(),' ');
if(m_error_call_stack[i].filename){
sstr<<"-- "<<" line:"<<m_error_call_stack[i].line<<" "<<m_error_call_stack[i].filename;
}
sstr<<endl;
sstr<<std::endl;
}
sstr<<"----------------------------"<<endl;
sstr<<"----------------------------"<<std::endl;

jout<<sstr.str();

Expand Down
11 changes: 5 additions & 6 deletions src/plugins/regressiontest/JEventProcessor_regressiontest.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
#ifndef _JEventProcessor_regressiontest_
#define _JEventProcessor_regressiontest_

#include <string>
#include <map>
#include <ostream>
#include <istream>

#include <JANA/JEventProcessor.h>

#include <fstream>
#include <map>
#include <string>


class JEventProcessor_regressiontest : public JEventProcessor
{
Expand Down Expand Up @@ -42,4 +41,4 @@ class JEventProcessor_regressiontest : public JEventProcessor
std::pair<std::string, int> ParseFactorySummary(std::string line);
};

#endif // _JEventProcessor_regressiontest_
#endif // _JEventProcessor_regressiontest_

0 comments on commit 1cd40ad

Please sign in to comment.