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
This commit is contained in:
hsc
2012-04-18 12:36:41 +00:00
parent 0963a06209
commit 1027b9faf2
2 changed files with 11 additions and 24 deletions

View File

@ -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) << "] ";
}

View File

@ -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<class T>
inline std::ostream& operator <<(const T& v)
{
std::stringstream ss;
ss << v;
add(ss.str());
return (*m_pDest);
timestamp();
return (*m_pDest) << v;
}
};