00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef BASICLOG_H
00023 #define BASICLOG_H
00024
00036 #include <fstream>
00037 #include <iostream>
00038 #include "basicobject.h"
00039
00054 class DECLSPEC BasicLog : public BasicObject
00055 {
00056 public:
00072 struct Logger
00073 {
00078 Logger( BasicLog *target, const char *strStart )
00079 {
00080 pTarget = target;
00081 pTarget->logBegin( strStart );
00082 bSuccess = false;
00083 }
00085 ~Logger()
00086 {
00087 pTarget->logEnd( bSuccess ? "done." : "failed." );
00088 }
00092 void line( const char * str )
00093 {
00094 pTarget->logLevelLine( str );
00095 }
00099 void append( const char * str )
00100 {
00101 pTarget->logString( str );
00102 }
00107 void succeede()
00108 {
00109 bSuccess = true;
00110 }
00111 private:
00112 BasicLog *pTarget;
00113 bool bSuccess;
00114 };
00121 DECLSPEC BasicLog( const char *name, BasicObject *parent, const char *filename );
00128 DECLSPEC BasicLog( const char *name, BasicObject *parent, std::ostream *strm = &std::cout );
00137 DECLSPEC BasicLog( TiXmlElement *el, BasicObject *p );
00138 virtual DECLSPEC ~BasicLog();
00139
00144 DECLSPEC void logLine( const char *ln );
00145
00149 DECLSPEC void logString( const char *str );
00154 DECLSPEC void logTime();
00155
00161 DECLSPEC void logBegin( const char *ln );
00162
00167 DECLSPEC void logLevel( const char *str );
00168
00173 DECLSPEC void logLevelLine( const char *ln );
00174
00180 DECLSPEC void logEnd( const char *ln );
00181
00189 DECLSPEC bool setDebug( bool dodebug );
00190
00194 DECLSPEC bool getDebug() { return bDebug; }
00195
00201 static DECLSPEC void logStdOut(const char *s);
00202
00203 protected:
00212 DECLSPEC bool initLogFile( const char *fn );
00218 DECLSPEC void initLogStream( std::ostream *strm );
00219 virtual DECLSPEC void onInit();
00220
00225 DECLSPEC bool bAutoLogTime;
00226
00227 private:
00228 bool bDebug;
00229 std::ofstream osLogFile;
00230 std::ostream *pLog;
00231 int nLogSpaces;
00232 };
00233
00234 #endif