1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-30 08:57:00 +02:00
vcmi/lib/CLogger.h

54 lines
1.3 KiB
C
Raw Normal View History

2011-12-14 00:35:28 +03:00
#pragma once
#include "CConsoleHandler.h"
extern DLL_LINKAGE std::ostream *logfile;
extern DLL_LINKAGE CConsoleHandler *console;
// CLogger, prints log info to console and saves in file
class DLL_LINKAGE CLogger
{
const int lvl;
#ifdef ANDROID
std::ostringstream buf;
int androidloglevel;
void outputAndroid();
#endif
public:
static const int CONSOLE_LOGGING_LEVEL;
static const int FILE_LOGGING_LEVEL;
CLogger& operator<<(std::ostream& (*fun)(std::ostream&));
template<typename T>
CLogger & operator<<(const T & data)
{
#ifdef ANDROID
buf << data;
outputAndroid();
#else
if(lvl < CLogger::CONSOLE_LOGGING_LEVEL)
{
if(console)
console->print(data, lvl);
else
std::cout << data << std::flush;
}
if((lvl < CLogger::FILE_LOGGING_LEVEL) && logfile)
*logfile << data << std::flush;
#endif
return *this;
}
CLogger(const int Lvl);
};
extern DLL_LINKAGE CLogger tlog0; //green - standard progress info
extern DLL_LINKAGE CLogger tlog1; //red - big errors
extern DLL_LINKAGE CLogger tlog2; //magenta - major warnings
extern DLL_LINKAGE CLogger tlog3; //yellow - minor warnings
extern DLL_LINKAGE CLogger tlog4; //white - detailed log info
extern DLL_LINKAGE CLogger tlog5; //gray - minor log info
extern DLL_LINKAGE CLogger tlog6; //teal - AI info