Skip to content

Commit

Permalink
JLogMessage uses JLogger's destination ostream
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwbrei committed Dec 13, 2024
1 parent b1fa752 commit 1f9d73b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/libraries/JANA/JLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,19 @@ inline std::ostream& operator<<(std::ostream& s, JLogger::Level l) {
class JLogMessage : public std::stringstream {
private:
std::string m_prefix;
std::ostream* m_destination;

public:
JLogMessage(const std::string& prefix="") : m_prefix(prefix){
JLogMessage(const std::string& prefix="") : m_prefix(prefix), m_destination(&std::cout){
}

JLogMessage(JLogMessage&& moved_from) : std::stringstream(std::move(moved_from)) {
m_prefix = moved_from.m_prefix;
m_destination = moved_from.m_destination;
}

JLogMessage(const JLogger& logger, JLogger::Level level) {
m_destination = logger.destination;
std::ostringstream builder;
if (logger.show_timestamp) {
auto now = std::chrono::system_clock::now();
Expand Down Expand Up @@ -112,8 +115,8 @@ class JLogMessage : public std::stringstream {
while (std::getline(*this, line)) {
oss << m_prefix << line << std::endl;
}
std::cout << oss.str();
std::cout.flush();
*m_destination << oss.str();
m_destination->flush();
}
};

Expand Down

0 comments on commit 1f9d73b

Please sign in to comment.