00001 #ifndef __Log__
00002 #define __Log__
00003 
00004 #include <iostream>
00005 #include <fstream>
00006 #include <string>
00007 
00008 #ifdef WIN32
00009         #include <Windows.h>
00010 #endif
00011 
00012 
00013 
00014 #ifdef NOTRACER
00015         #pragma warning( disable : 4002) 
00016         #define TRACE()
00017         #define TRACEX()
00018 #else
00019         #define TRACE(a) myLog.Trace((a));
00020         #ifdef WIN32
00021                 #define TRACEX(lvl, fmt, ...) { char cc[200]; sprintf_s(cc, fmt, __VA_ARGS__); myLog.Trace((cc), (lvl)); }
00022         #else
00023                 #define TRACEX(lvl, fmt, ...) { char cc[200]; sprintf(cc, fmt, ## __VA_ARGS__); myLog.Trace((cc), (lvl)); }
00024         #endif
00025 #endif
00026 
00027 
00028 enum Level
00029 {
00030         lvDebug,
00031         lvInfo,
00032         lvWarning, 
00033         lvError, 
00034         lvFatal
00035 };
00036 
00037 
00038 
00039 class Log
00040 {
00041 public:
00042         char* filename;
00043         char* prefix;
00044         Level filter;
00045         bool consoleOutput;
00046         bool useDebugData;
00047         int steps;
00048 
00049         Log();
00050         Log(char* _filename, Level _filter=lvDebug, char* _prefix=0, bool _consoleOutput=false);
00051         void Setup(char* _filename, Level _filter=lvDebug, char* _prefix=0, bool _consoleOutput=false);
00052 
00053         ~Log();
00054 
00055         void Trace(char* message, int _severity=lvWarning);
00056 
00057 private:
00058         std::ofstream* file;
00059         int step;
00060 
00061         #ifdef WIN32
00062                 LONGLONG ticksPerSecond;
00063                 LONGLONG deltaT;
00064                 int GetMicroseconds();
00065         #endif
00066         
00067         
00068         std::string GetTimeString();
00069         std::string GetDebugData();
00070         void Init();
00071 };
00072 
00073 #endif