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
| // Class : Logger
// > Doing < It's a tool to mainly help the debugging process . We can retrieve informations when we want,
// --------- where we want, and how we want.
// > Todo < Define the exact output types.
// --------- Maybe change the way the FileOutput works (it just adds to the end of the file each time we log)
// --------- FileOutPut is temporary , till a final format is chosen (xml?)
// > How < Use the macro Log(Msg Type,Output Type) and the operator << .
// --------- Enable or disable some log with the "Msg Type" Macro.
// >>>>>>>>> Adrien LAMBERT - 2005 / 2006
#ifndef LOGGER_HPP
#define LOGGER_HPP
// Output Type (Flags)
#define LOG_FILE 0x00000001
#define LOG_SCREEN 0x00000002
#define LOG_CONSOLE 0x00000004
#define LOG_ALL LOG_FILE | LOG_SCREEN | LOG_CONSOLE
// Msg Type (1 = Log / 0 = Don't)
#define LOG_WARNING 1
#define LOG_ERROR 1
#define LOG_MISC 1
#define Log(flag,type) Logger<type == 1>(flag,__FILE__,__FUNCTION__,__LINE__)
// Standard includes
#include <sstream>
#include <iostream>
#include <fstream>
// Template, general declaration
template<bool DoLog> class Logger;
// Template version, if we actually want to log something .
template<> class Logger<true>
{
public :
Logger(unsigned char Flag,const char * File, const char * Function,int Line)
: Flag_(Flag),
File_(File),
Function_(Function),
Line_(Line),
FileName_("Log.txt")
{
}
~Logger()
{
if ( Flag_ & LOG_FILE )
{
std::ofstream FileStream(FileName_,std::ios_base::app);
FileStream << Msg_.str() ;
}
if ( Flag_ & LOG_SCREEN )
{ /* TODO */ }
if ( Flag_ & LOG_CONSOLE )
{ /* TODO */ }
}
template<typename T> Logger & operator << (T const & t) { Msg_ << t; return * this; }
private:
// Data
std::stringstream Msg_;
unsigned char Flag_ ;
const char * File_ ;
const char * Function_ ;
int Line_ ;
const char * FileName_;
};
// Template version, if we do NOT want to log .
template<> class Logger<false>
{
public :
Logger(unsigned char Flag,const char * File, const char * Function,int Line){}
~Logger(){}
template<typename T> Logger& operator<<(T const & t) { return * this; }
};
#endif // LOGGER_HPP |
Partager