Streamline Log with print() and out()

This commit is contained in:
Vinnie Falco
2013-06-30 12:11:42 -07:00
parent c35c52ff08
commit b52bbccd8a
25 changed files with 174 additions and 81 deletions

View File

@@ -117,6 +117,63 @@ public:
static std::string rotateLog ();
public:
/** Write to log output.
All logging eventually goes through this function. If a
debugger is attached, the string goes to the debugging console,
else it goes to the standard error output. If a log file is
open, then the message is additionally written to the open log
file.
The text should not contain a newline, it will be automatically
added as needed.
@note This acquires a global mutex.
@param text The text to write.
@param toStdErr `true` to also write to std::cerr
*/
static void print (std::string const& text,
bool toStdErr = true);
/** Output stream for logging
This is a convenient replacement for writing to `std::cerr`.
Usage:
@code
Log::out () << "item1" << 2;
@endcode
It is not necessary to append a newline.
*/
class out
{
public:
out ()
{
}
~out ()
{
Log::print (m_ss.str ());
}
template <class T>
out& operator<< (T t)
{
m_ss << t;
return *this;
}
private:
std::stringstream m_ss;
};
private:
enum
{