mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-23 00:28:08 +02:00
More logging for #520
This commit is contained in:
29
global.h
29
global.h
@ -311,10 +311,13 @@ void delNull(T* &ptr) //deleted pointer and sets it to NULL
|
|||||||
#include "CConsoleHandler.h"
|
#include "CConsoleHandler.h"
|
||||||
extern DLL_EXPORT std::ostream *logfile;
|
extern DLL_EXPORT std::ostream *logfile;
|
||||||
extern DLL_EXPORT CConsoleHandler *console;
|
extern DLL_EXPORT CConsoleHandler *console;
|
||||||
template <int lvl> class CLogger //logger, prints log info to console and saves in file
|
|
||||||
|
class CLogger //logger, prints log info to console and saves in file
|
||||||
{
|
{
|
||||||
|
const int lvl;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CLogger<lvl>& operator<<(std::ostream& (*fun)(std::ostream&))
|
CLogger& operator<<(std::ostream& (*fun)(std::ostream&))
|
||||||
{
|
{
|
||||||
if(lvl < CONSOLE_LOGGING_LEVEL)
|
if(lvl < CONSOLE_LOGGING_LEVEL)
|
||||||
std::cout << fun;
|
std::cout << fun;
|
||||||
@ -324,33 +327,29 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
CLogger<lvl> & operator<<(const T & data)
|
CLogger & operator<<(const T & data)
|
||||||
{
|
{
|
||||||
if(lvl < CONSOLE_LOGGING_LEVEL)
|
if(lvl < CONSOLE_LOGGING_LEVEL)
|
||||||
{
|
{
|
||||||
if(console)
|
if(console)
|
||||||
{
|
|
||||||
console->print(data,lvl);
|
console->print(data,lvl);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
std::cout << data << std::flush;
|
std::cout << data << std::flush;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if((lvl < FILE_LOGGING_LEVEL) && logfile)
|
if((lvl < FILE_LOGGING_LEVEL) && logfile)
|
||||||
{
|
|
||||||
*logfile << data << std::flush;
|
*logfile << data << std::flush;
|
||||||
}
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CLogger(const int Lvl) : lvl(Lvl) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
extern DLL_EXPORT CLogger<0> tlog0; //green - standard progress info
|
extern DLL_EXPORT CLogger tlog0; //green - standard progress info
|
||||||
extern DLL_EXPORT CLogger<1> tlog1; //red - big errors
|
extern DLL_EXPORT CLogger tlog1; //red - big errors
|
||||||
extern DLL_EXPORT CLogger<2> tlog2; //magenta - major warnings
|
extern DLL_EXPORT CLogger tlog2; //magenta - major warnings
|
||||||
extern DLL_EXPORT CLogger<3> tlog3; //yellow - minor warnings
|
extern DLL_EXPORT CLogger tlog3; //yellow - minor warnings
|
||||||
extern DLL_EXPORT CLogger<4> tlog4; //white - detailed log info
|
extern DLL_EXPORT CLogger tlog4; //white - detailed log info
|
||||||
extern DLL_EXPORT CLogger<5> tlog5; //gray - minor log info
|
extern DLL_EXPORT CLogger tlog5; //gray - minor log info
|
||||||
|
|
||||||
//XXX pls dont - 'debug macros' are usually more trouble than it's worth
|
//XXX pls dont - 'debug macros' are usually more trouble than it's worth
|
||||||
#define HANDLE_EXCEPTION \
|
#define HANDLE_EXCEPTION \
|
||||||
|
@ -412,6 +412,7 @@ void CHeroHandler::loadHeroes()
|
|||||||
std::ifstream inp;
|
std::ifstream inp;
|
||||||
dump.clear();
|
dump.clear();
|
||||||
inp.open(DATA_DIR "/config/specials.txt"); //loading hero specials
|
inp.open(DATA_DIR "/config/specials.txt"); //loading hero specials
|
||||||
|
assert(inp);
|
||||||
specialInfo dummy;
|
specialInfo dummy;
|
||||||
si32 hid;
|
si32 hid;
|
||||||
inp.ignore(100, '\n');
|
inp.ignore(100, '\n');
|
||||||
|
@ -208,6 +208,16 @@ bool CConnection::isOpen() const
|
|||||||
return socket && connected;
|
return socket && connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CConnection::reportState(CLogger &out)
|
||||||
|
{
|
||||||
|
out << "CConnection\n";
|
||||||
|
if(socket && socket->is_open())
|
||||||
|
{
|
||||||
|
out << "\tWe have an open and valid socket\n";
|
||||||
|
out << "\t" << socket->available() <<" bytes awaiting\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CSaveFile::CSaveFile( const std::string &fname )
|
CSaveFile::CSaveFile( const std::string &fname )
|
||||||
:sfile(NULL)
|
:sfile(NULL)
|
||||||
{
|
{
|
||||||
@ -234,6 +244,7 @@ void CSaveFile::close()
|
|||||||
|
|
||||||
void CSaveFile::openNextFile(const std::string &fname)
|
void CSaveFile::openNextFile(const std::string &fname)
|
||||||
{
|
{
|
||||||
|
fName = fname;
|
||||||
close();
|
close();
|
||||||
sfile = new std::ofstream(fname.c_str(),std::ios::binary);
|
sfile = new std::ofstream(fname.c_str(),std::ios::binary);
|
||||||
if(!(*sfile))
|
if(!(*sfile))
|
||||||
@ -248,6 +259,15 @@ void CSaveFile::openNextFile(const std::string &fname)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSaveFile::reportState(CLogger &out)
|
||||||
|
{
|
||||||
|
out << "CSaveFile" << std::endl;
|
||||||
|
if(sfile && *sfile)
|
||||||
|
{
|
||||||
|
out << "\tOpened " << fName << "\n\tPosition: " << sfile->tellp() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CLoadFile::CLoadFile( const std::string &fname, bool requireLatest )
|
CLoadFile::CLoadFile( const std::string &fname, bool requireLatest )
|
||||||
:sfile(NULL)
|
:sfile(NULL)
|
||||||
{
|
{
|
||||||
@ -274,6 +294,7 @@ void CLoadFile::close()
|
|||||||
|
|
||||||
void CLoadFile::openNextFile(const std::string &fname, bool requireLatest)
|
void CLoadFile::openNextFile(const std::string &fname, bool requireLatest)
|
||||||
{
|
{
|
||||||
|
fName = fname;
|
||||||
sfile = new std::ifstream(fname.c_str(),std::ios::binary);
|
sfile = new std::ifstream(fname.c_str(),std::ios::binary);
|
||||||
if(!(*sfile))
|
if(!(*sfile))
|
||||||
{
|
{
|
||||||
@ -303,6 +324,15 @@ void CLoadFile::openNextFile(const std::string &fname, bool requireLatest)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CLoadFile::reportState(CLogger &out)
|
||||||
|
{
|
||||||
|
out << "CLoadFile" << std::endl;
|
||||||
|
if(sfile && *sfile)
|
||||||
|
{
|
||||||
|
out << "\tOpened " << fName << "\n\tPosition: " << sfile->tellg() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CTypeList::CTypeList()
|
CTypeList::CTypeList()
|
||||||
{
|
{
|
||||||
registerTypes(*this);
|
registerTypes(*this);
|
||||||
|
@ -251,6 +251,8 @@ public:
|
|||||||
CSerializer();
|
CSerializer();
|
||||||
~CSerializer();
|
~CSerializer();
|
||||||
|
|
||||||
|
virtual void reportState(CLogger &out){};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void registerVectoredType(const std::vector<T*> *Vector, const si32 T::*IdPtr)
|
void registerVectoredType(const std::vector<T*> *Vector, const si32 T::*IdPtr)
|
||||||
{
|
{
|
||||||
@ -722,11 +724,20 @@ public:
|
|||||||
loadedPointers[pid] = (void*)ptr; //add loaded pointer to our lookup map; cast is to avoid errors with const T* pt
|
loadedPointers[pid] = (void*)ptr; //add loaded pointer to our lookup map; cast is to avoid errors with const T* pt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define READ_CHECK_U32(x) \
|
||||||
|
boost::uint32_t length; \
|
||||||
|
*this >> length; \
|
||||||
|
if(length > 50000) \
|
||||||
|
{ \
|
||||||
|
tlog2 << "Warning: very big length: " << length << "\n" ;\
|
||||||
|
reportState(tlog2); \
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void loadSerializable(std::vector<T> &data)
|
void loadSerializable(std::vector<T> &data)
|
||||||
{
|
{
|
||||||
boost::uint32_t length;
|
READ_CHECK_U32(length);
|
||||||
*this >> length;
|
|
||||||
data.resize(length);
|
data.resize(length);
|
||||||
for(ui32 i=0;i<length;i++)
|
for(ui32 i=0;i<length;i++)
|
||||||
*this >> data[i];
|
*this >> data[i];
|
||||||
@ -734,8 +745,7 @@ public:
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
void loadSerializable(std::set<T> &data)
|
void loadSerializable(std::set<T> &data)
|
||||||
{
|
{
|
||||||
boost::uint32_t length;
|
READ_CHECK_U32(length);
|
||||||
*this >> length;
|
|
||||||
T ins;
|
T ins;
|
||||||
for(ui32 i=0;i<length;i++)
|
for(ui32 i=0;i<length;i++)
|
||||||
{
|
{
|
||||||
@ -746,8 +756,7 @@ public:
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
void loadSerializable(std::list<T> &data)
|
void loadSerializable(std::list<T> &data)
|
||||||
{
|
{
|
||||||
boost::uint32_t length;
|
READ_CHECK_U32(length);
|
||||||
*this >> length;
|
|
||||||
T ins;
|
T ins;
|
||||||
for(ui32 i=0;i<length;i++)
|
for(ui32 i=0;i<length;i++)
|
||||||
{
|
{
|
||||||
@ -764,8 +773,7 @@ public:
|
|||||||
template <typename T1, typename T2>
|
template <typename T1, typename T2>
|
||||||
void loadSerializable(std::map<T1,T2> &data)
|
void loadSerializable(std::map<T1,T2> &data)
|
||||||
{
|
{
|
||||||
ui32 length;
|
READ_CHECK_U32(length);
|
||||||
*this >> length;
|
|
||||||
T1 t;
|
T1 t;
|
||||||
for(ui32 i=0;i<length;i++)
|
for(ui32 i=0;i<length;i++)
|
||||||
{
|
{
|
||||||
@ -775,8 +783,7 @@ public:
|
|||||||
}
|
}
|
||||||
void loadSerializable(std::string &data)
|
void loadSerializable(std::string &data)
|
||||||
{
|
{
|
||||||
ui32 length;
|
READ_CHECK_U32(length);
|
||||||
*this >> length;
|
|
||||||
data.resize(length);
|
data.resize(length);
|
||||||
this->This()->read((void*)data.c_str(),length);
|
this->This()->read((void*)data.c_str(),length);
|
||||||
}
|
}
|
||||||
@ -792,13 +799,16 @@ class DLL_EXPORT CSaveFile
|
|||||||
*this << std::string("This function makes stuff working.");
|
*this << std::string("This function makes stuff working.");
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
|
std::string fName;
|
||||||
std::ofstream *sfile;
|
std::ofstream *sfile;
|
||||||
|
|
||||||
CSaveFile(const std::string &fname);
|
CSaveFile(const std::string &fname);
|
||||||
~CSaveFile();
|
~CSaveFile();
|
||||||
int write(const void * data, unsigned size);
|
int write(const void * data, unsigned size);
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
void openNextFile(const std::string &fname);
|
void openNextFile(const std::string &fname);
|
||||||
|
void reportState(CLogger &out);
|
||||||
};
|
};
|
||||||
|
|
||||||
class DLL_EXPORT CLoadFile
|
class DLL_EXPORT CLoadFile
|
||||||
@ -810,13 +820,16 @@ class DLL_EXPORT CLoadFile
|
|||||||
*this >> dummy;
|
*this >> dummy;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
|
std::string fName;
|
||||||
std::ifstream *sfile;
|
std::ifstream *sfile;
|
||||||
|
|
||||||
CLoadFile(const std::string &fname, bool requireLatest = true);
|
CLoadFile(const std::string &fname, bool requireLatest = true);
|
||||||
~CLoadFile();
|
~CLoadFile();
|
||||||
int read(const void * data, unsigned size);
|
int read(const void * data, unsigned size);
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
void openNextFile(const std::string &fname, bool requireLatest);
|
void openNextFile(const std::string &fname, bool requireLatest);
|
||||||
|
void reportState(CLogger &out);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef boost::asio::basic_stream_socket < boost::asio::ip::tcp , boost::asio::stream_socket_service<boost::asio::ip::tcp> > TSocket;
|
typedef boost::asio::basic_stream_socket < boost::asio::ip::tcp , boost::asio::stream_socket_service<boost::asio::ip::tcp> > TSocket;
|
||||||
@ -829,6 +842,7 @@ class DLL_EXPORT CConnection
|
|||||||
CConnection(void);
|
CConnection(void);
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
void reportState(CLogger &out);
|
||||||
public:
|
public:
|
||||||
boost::mutex *rmx, *wmx; // read/write mutexes
|
boost::mutex *rmx, *wmx; // read/write mutexes
|
||||||
TSocket * socket;
|
TSocket * socket;
|
||||||
|
@ -27,12 +27,12 @@ LibClasses * VLC = NULL;
|
|||||||
DLL_EXPORT CLodHandler *bitmaph = NULL,
|
DLL_EXPORT CLodHandler *bitmaph = NULL,
|
||||||
*spriteh = NULL;
|
*spriteh = NULL;
|
||||||
|
|
||||||
DLL_EXPORT CLogger<0> tlog0;
|
DLL_EXPORT CLogger tlog0(0);
|
||||||
DLL_EXPORT CLogger<1> tlog1;
|
DLL_EXPORT CLogger tlog1(1);
|
||||||
DLL_EXPORT CLogger<2> tlog2;
|
DLL_EXPORT CLogger tlog2(2);
|
||||||
DLL_EXPORT CLogger<3> tlog3;
|
DLL_EXPORT CLogger tlog3(3);
|
||||||
DLL_EXPORT CLogger<4> tlog4;
|
DLL_EXPORT CLogger tlog4(4);
|
||||||
DLL_EXPORT CLogger<5> tlog5;
|
DLL_EXPORT CLogger tlog5(5);
|
||||||
|
|
||||||
DLL_EXPORT CConsoleHandler *console = NULL;
|
DLL_EXPORT CConsoleHandler *console = NULL;
|
||||||
DLL_EXPORT std::ostream *logfile = NULL
|
DLL_EXPORT std::ostream *logfile = NULL
|
||||||
|
Reference in New Issue
Block a user