From 1027b9faf2f9829d073f79505002430b698ad6f1 Mon Sep 17 00:00:00 2001 From: hsc Date: Wed, 18 Apr 2012 12:36:41 +0000 Subject: [PATCH] Logger: fixed the case when the first << operand is a manipulator log << std::dec << 123; failed before. Simplified the whole Logger class, removed add() functions nobody wants to use anyways. git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1097 8c4709b5-6ec9-48aa-a5cd-a96041d1645a --- core/util/Logger.cc | 11 +++++------ core/util/Logger.hpp | 24 ++++++------------------ 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/core/util/Logger.cc b/core/util/Logger.cc index a32f0196..a2271c46 100644 --- a/core/util/Logger.cc +++ b/core/util/Logger.cc @@ -10,14 +10,13 @@ using std::endl; -void Logger::add(const std::string& what, const std::string& descr) +void Logger::timestamp() { - (*m_pDest) << "[" << descr; - if(m_showTime) - { + (*m_pDest) << "[" << m_description; + if (m_showTime) { time_t rawtime; struct tm* timeinfo; - char buffer [80]; + char buffer[80]; time(&rawtime); timeinfo = localtime(&rawtime); @@ -25,5 +24,5 @@ void Logger::add(const std::string& what, const std::string& descr) strftime(buffer, 80, "%H:%M:%S", timeinfo); (*m_pDest) << " " << buffer; } - (*m_pDest) << "] " << what; + (*m_pDest) << "] "; } diff --git a/core/util/Logger.hpp b/core/util/Logger.hpp index f98009c9..9f0f57b9 100644 --- a/core/util/Logger.hpp +++ b/core/util/Logger.hpp @@ -17,6 +17,8 @@ class Logger std::ostream* m_pDest; std::string m_description; bool m_showTime; + void timestamp(); + public: /** * Constructor. @@ -38,29 +40,15 @@ class Logger m_description = descr; } /** - * Add a new log entry. - * @param what Message for log entry. - * @param descr Description shown alongside this log entry in square - * brackets [ ]. - */ - void add(const std::string& what, const std::string& descr); - /** - * Add a new log entry. - * @param what Message for log entry. The default description is - * being used in square brackets [ ]. - */ - void add(const std::string& what) { add(what, m_description); } - /** - * Simplifies the logging. + * Add a new log entry. Returns a std::ostream reference to continue + * streaming a longer log entry. * @param v data to log */ template inline std::ostream& operator <<(const T& v) { - std::stringstream ss; - ss << v; - add(ss.str()); - return (*m_pDest); + timestamp(); + return (*m_pDest) << v; } };