From 636eb83fc7f9778d6ab037af968092437c18b16b Mon Sep 17 00:00:00 2001 From: Victor Kotlyar <Victor.Kotlyar@cern.ch> Date: Wed, 9 Aug 2017 14:47:13 +0200 Subject: [PATCH] Fix position for the "status" parameter for "Tape thread complete" and "Tape session finished" cta-taped log messages always be on the end. --- common/log/LogContext.cpp | 11 +++++++++++ common/log/LogContext.hpp | 8 ++++++++ .../tape/tapeserver/daemon/TapeReadSingleThread.cpp | 1 + .../tape/tapeserver/daemon/TapeWriteSingleThread.cpp | 1 + tapeserver/daemon/DriveHandler.cpp | 1 + 5 files changed, 22 insertions(+) diff --git a/common/log/LogContext.cpp b/common/log/LogContext.cpp index 258cc5655e..335d3c0ff9 100644 --- a/common/log/LogContext.cpp +++ b/common/log/LogContext.cpp @@ -41,6 +41,17 @@ void LogContext::pushOrReplace(const Param& param) throw() { } } +void LogContext::moveToTheEndIfPresent(const std::string& paramName) throw() { + ParamNameMatcher match(paramName); + std::list<Param>::iterator i = + std::find_if(m_params.begin(), m_params.end(), match); + if (i != m_params.end()) { + const Param param(paramName,i->getValue()); + m_params.erase(i); + m_params.push_back(param); + } +} + void LogContext::erase(const std::string& paramName) throw() { ParamNameMatcher match(paramName); m_params.erase(std::remove_if(m_params.begin(), m_params.end(), match), m_params.end()); diff --git a/common/log/LogContext.hpp b/common/log/LogContext.hpp index 09b13e0814..92be7db115 100644 --- a/common/log/LogContext.hpp +++ b/common/log/LogContext.hpp @@ -59,6 +59,14 @@ public: * @param param */ void pushOrReplace(const Param & param) throw(); + + /** + * Move a parameter with a given name to the end of the container it it + * present. + * + * @param paramName The name of the parameter to check and move. + */ + void moveToTheEndIfPresent(const std::string ¶mName) throw(); /** * Removes a parameter from the list. diff --git a/tapeserver/castor/tape/tapeserver/daemon/TapeReadSingleThread.cpp b/tapeserver/castor/tape/tapeserver/daemon/TapeReadSingleThread.cpp index e0ccfbf1ce..563bb7cf16 100644 --- a/tapeserver/castor/tape/tapeserver/daemon/TapeReadSingleThread.cpp +++ b/tapeserver/castor/tape/tapeserver/daemon/TapeReadSingleThread.cpp @@ -394,6 +394,7 @@ void castor::tape::tapeserver::daemon::TapeReadSingleThread::logWithStat( /1000/1000/m_stats.totalTime:0.0) .add("driveTransferSpeedMBps", m_stats.totalTime?1.0*(m_stats.dataVolume+m_stats.headerVolume) /1000/1000/m_stats.totalTime:0.0); + m_logContext.moveToTheEndIfPresent("status"); m_logContext.log(level,msg); } diff --git a/tapeserver/castor/tape/tapeserver/daemon/TapeWriteSingleThread.cpp b/tapeserver/castor/tape/tapeserver/daemon/TapeWriteSingleThread.cpp index 07e1533020..c4bfb0452b 100644 --- a/tapeserver/castor/tape/tapeserver/daemon/TapeWriteSingleThread.cpp +++ b/tapeserver/castor/tape/tapeserver/daemon/TapeWriteSingleThread.cpp @@ -529,6 +529,7 @@ int level,const std::string& msg, cta::log::ScopedParamContainer& params){ /1000/1000/m_stats.totalTime:0.0) .add("driveTransferSpeedMBps", m_stats.totalTime?1.0*(m_stats.dataVolume+m_stats.headerVolume) /1000/1000/m_stats.totalTime:0.0); + m_logContext.moveToTheEndIfPresent("status"); m_logContext.log(level, msg); } diff --git a/tapeserver/daemon/DriveHandler.cpp b/tapeserver/daemon/DriveHandler.cpp index 13c2d121c0..caa1ba8170 100644 --- a/tapeserver/daemon/DriveHandler.cpp +++ b/tapeserver/daemon/DriveHandler.cpp @@ -764,6 +764,7 @@ SubprocessHandler::ProcessingStatus DriveHandler::processSigChild() { m_sessionEndContext.pushOrReplace({"status", "failure"}); } // In all cases we log the end of the session. + m_sessionEndContext.moveToTheEndIfPresent("status"); m_sessionEndContext.log(cta::log::INFO, "Tape session finished"); m_sessionEndContext.clear(); // And record we do not have a process anymore. -- GitLab