mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
Log and queue added
This commit is contained in:
parent
d07f5d0310
commit
465075d825
3 changed files with 149 additions and 0 deletions
45
Log.h
Normal file
45
Log.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
#ifndef LOG_H__
|
||||
#define LOG_H__
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "Queue.h"
|
||||
|
||||
struct LogMsg
|
||||
{
|
||||
std::stringstream s;
|
||||
std::ostream& output;
|
||||
|
||||
LogMsg (std::ostream& o = std::cout): output (o) {};
|
||||
|
||||
void Process ()
|
||||
{
|
||||
output << s.str ();
|
||||
}
|
||||
};
|
||||
|
||||
extern i2p::util::MsgQueue<LogMsg> g_Log;
|
||||
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue