1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#include <iostream>
#include <string>
#include <ostream>
#include <sstream>
#include <vector>
typedef enum
{
Trivial,
Normal,
Critical
}LogLevel;
class LogChannel
{
public:
LogChannel(const std::wstring &Name)
: m_Name(Name), m_CurrentLogLevel(Normal)
{
}
template <typename Type>
LogChannel &operator<<(const Type &Value)
{
std::wcout << Value;
return *this;
}
template <typename _CharT, typename _Traits>
LogChannel &operator <<(std::ostream (*fp)(std::basic_ostream<_CharT, _Traits> &__os))
{
std::wcout << "End line detected...";
return *this;
}
// private:
// Must use wide string...
LogChannel &operator<<(const char *pString)
{
return *this;
}
protected:
const std::wstring m_Name;
std::wostringstream m_CurrentEntry;
LogLevel m_CurrentLogLevel;
};
class LogManager
{
public:
typedef enum
{
AI,
Audio,
Event,
General,
Physics
}ChannelID;
LogManager()
{
m_Channels.push_back(new LogChannel(L"AI"));
m_Channels.push_back(new LogChannel(L"Audio"));
m_Channels.push_back(new LogChannel(L"Event"));
m_Channels.push_back(new LogChannel(L"General"));
m_Channels.push_back(new LogChannel(L"Physics"));
}
LogChannel & operator()(const ChannelID Channel, const LogLevel Level)
{
return *m_Channels.at(Channel);
}
~LogManager()
{
for(unsigned int Index = 0; Index < m_Channels.size(); ++Index)
delete m_Channels.at(Index);
}
protected:
std::vector<LogChannel *> m_Channels;
};
LogManager m_LogManager;
#define LogPhysics(Level) m_LogManager(LogManager::Physics, (Level))
int main()
{
//m_LogManager(LogManager::Physics, Normal) << L"Some physics stuff on line " << __LINE__ << '\n';
//m_LogManager(LogManager::Physics, Normal) << std::endl;
LogPhysics(Normal) << "Some physics stuff on line " << __LINE__ << std::endl;
return 0;
}
|