From 1f9d73b02076e141fcaf579af140f2d8d532f27f Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Fri, 13 Dec 2024 16:36:07 -0500 Subject: [PATCH] JLogMessage uses JLogger's destination ostream --- src/libraries/JANA/JLogger.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libraries/JANA/JLogger.h b/src/libraries/JANA/JLogger.h index 0fa8d6702..42b20ef95 100644 --- a/src/libraries/JANA/JLogger.h +++ b/src/libraries/JANA/JLogger.h @@ -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(); @@ -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(); } };