2013-12-10 17:00:13 +04:00
|
|
|
#ifndef LOG_H__
|
|
|
|
#define LOG_H__
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2014-04-23 20:49:02 +04:00
|
|
|
#include <functional>
|
2013-12-10 17:00:13 +04:00
|
|
|
#include "Queue.h"
|
|
|
|
|
|
|
|
struct LogMsg
|
|
|
|
{
|
|
|
|
std::stringstream s;
|
|
|
|
std::ostream& output;
|
|
|
|
|
|
|
|
LogMsg (std::ostream& o = std::cout): output (o) {};
|
|
|
|
|
2014-04-23 02:10:21 +04:00
|
|
|
void Process();
|
2013-12-10 17:00:13 +04:00
|
|
|
};
|
|
|
|
|
2014-04-23 20:49:02 +04:00
|
|
|
class Log: public i2p::util::MsgQueue<LogMsg>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Log () { SetOnEmpty (std::bind (&Log::Flush, this)); };
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void Flush ();
|
|
|
|
};
|
|
|
|
|
|
|
|
extern Log g_Log;
|
2013-12-10 17:00:13 +04:00
|
|
|
|
|
|
|
template<typename TValue>
|
|
|
|
void LogPrint (std::stringstream& s, TValue arg)
|
|
|
|
{
|
|
|
|
s << arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename TValue, typename... TArgs>
|
|
|
|
void LogPrint (std::stringstream& s, TValue arg, TArgs... args)
|
|
|
|
{
|
|
|
|
LogPrint (s, arg);
|
|
|
|
LogPrint (s, args...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename... TArgs>
|
|
|
|
void LogPrint (TArgs... args)
|
|
|
|
{
|
|
|
|
LogMsg * msg = new LogMsg ();
|
|
|
|
LogPrint (msg->s, args...);
|
|
|
|
msg->s << std::endl;
|
|
|
|
g_Log.Put (msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|