From f8372e248056b1e92deb6504f291ecabedf925f5 Mon Sep 17 00:00:00 2001
From: Eric Cano <Eric.Cano@cern.ch>
Date: Wed, 1 Feb 2017 15:55:53 +0100
Subject: [PATCH] Moved newline responsiblility from in logger.

The log line creation function Logger::writeLogMsg does not add the trailing newine.
Instead, the overloads of reducedSyslog() do, il needed and after possible line truncation.
---
 common/log/FileLogger.cpp   | 2 +-
 common/log/FileLogger.hpp   | 4 +++-
 common/log/Logger.cpp       | 3 ---
 common/log/StdoutLogger.cpp | 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/common/log/FileLogger.cpp b/common/log/FileLogger.cpp
index a99f6e5e76..6cc7e92807 100644
--- a/common/log/FileLogger.cpp
+++ b/common/log/FileLogger.cpp
@@ -60,7 +60,7 @@ void FileLogger::reducedSyslog(const std::string & msg) {
   if (-1 == m_fd)
     throw cta::exception::Exception("In FileLogger::reducedSyslog(): file is not properly initialized");
   // Prepare the string to print (for size)
-  std::string m = msg.substr(0, m_maxMsgLen);
+  std::string m = msg.substr(0, m_maxMsgLen) + "\n";
   
   // enter critical section
   threading::MutexLocker lock(m_mutex);
diff --git a/common/log/FileLogger.hpp b/common/log/FileLogger.hpp
index 9737226579..14e36a8ee8 100644
--- a/common/log/FileLogger.hpp
+++ b/common/log/FileLogger.hpp
@@ -70,7 +70,9 @@ protected:
   /**
    * A reduced version of syslog.  This method is able to set the message
    * timestamp.  This is necessary when logging messages asynchronously of there
-   * creation, such as when retrieving logs from the DB.
+   * creation, such as when retrieving logs from the DB. This function truncates 
+   * the message if necessary. It also adds a new line at the end of the message 
+   * if needed.
    *
    * @param msg The message to be logged.
    */
diff --git a/common/log/Logger.cpp b/common/log/Logger.cpp
index 5247f576c0..4021a901ba 100644
--- a/common/log/Logger.cpp
+++ b/common/log/Logger.cpp
@@ -153,9 +153,6 @@ void Logger::writeLogMsg(
 
   // Append raw parameters
   os << rawParams;
-
-  // Terminate the string
-  os << "\n";
 }
 
 //-----------------------------------------------------------------------------
diff --git a/common/log/StdoutLogger.cpp b/common/log/StdoutLogger.cpp
index bb19cc0eac..5cb46251ee 100644
--- a/common/log/StdoutLogger.cpp
+++ b/common/log/StdoutLogger.cpp
@@ -43,7 +43,7 @@ void StdoutLogger::prepareForFork() {}
 // reducedSyslog
 //------------------------------------------------------------------------------
 void StdoutLogger::reducedSyslog(const std::string & msg) {
-  printf("%s", msg.c_str());
+  printf("%s\n", msg.c_str());
 }
 
 } // namespace log
-- 
GitLab