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:
@ -10,14 +10,13 @@
|
|||||||
|
|
||||||
using std::endl;
|
using std::endl;
|
||||||
|
|
||||||
void Logger::add(const std::string& what, const std::string& descr)
|
void Logger::timestamp()
|
||||||
{
|
{
|
||||||
(*m_pDest) << "[" << descr;
|
(*m_pDest) << "[" << m_description;
|
||||||
if(m_showTime)
|
if (m_showTime) {
|
||||||
{
|
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm* timeinfo;
|
struct tm* timeinfo;
|
||||||
char buffer [80];
|
char buffer[80];
|
||||||
|
|
||||||
time(&rawtime);
|
time(&rawtime);
|
||||||
timeinfo = localtime(&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);
|
strftime(buffer, 80, "%H:%M:%S", timeinfo);
|
||||||
(*m_pDest) << " " << buffer;
|
(*m_pDest) << " " << buffer;
|
||||||
}
|
}
|
||||||
(*m_pDest) << "] " << what;
|
(*m_pDest) << "] ";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,8 @@ class Logger
|
|||||||
std::ostream* m_pDest;
|
std::ostream* m_pDest;
|
||||||
std::string m_description;
|
std::string m_description;
|
||||||
bool m_showTime;
|
bool m_showTime;
|
||||||
|
void timestamp();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -38,29 +40,15 @@ class Logger
|
|||||||
m_description = descr;
|
m_description = descr;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Add a new log entry.
|
* Add a new log entry. Returns a std::ostream reference to continue
|
||||||
* @param what Message for log entry.
|
* streaming a longer 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.
|
|
||||||
* @param v data to log
|
* @param v data to log
|
||||||
*/
|
*/
|
||||||
template<class T>
|
template<class T>
|
||||||
inline std::ostream& operator <<(const T& v)
|
inline std::ostream& operator <<(const T& v)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
timestamp();
|
||||||
ss << v;
|
return (*m_pDest) << v;
|
||||||
add(ss.str());
|
|
||||||
return (*m_pDest);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user