00001
00002
00003 #ifndef AS_LOG_H
00004 #define AS_LOG_H
00005
00006 #include <iostream.h>
00007
00008 #include <string>
00009 #include <pthread.h>
00010
00011 #ifdef DEBUGLOG
00012
00013 #define LOG_OPEN(X)
00014 #define LOG(X)
00015 #define LOGL(Y,X)
00016 #define LOG_CLOSE()
00017 #define DB_AND_LOG(X)
00018 #define DB_AND_LOGL(Y,X)
00019 #define DB_AND_LOG_STAT(X)
00020 #define DB_AND_LOGL_STAT(Y,X)
00021 #define LOG_STAT(X)
00022 #define LOGL_STAT(Y,X)
00023
00024 #else
00025
00026 #define LOG_OPEN(X) \
00027 Log::open(X)
00028
00029 #define LOG(X) \
00030 if (Log::log_out) \
00031 { \
00032 *Log::log_out << Log::localtime() << " " << pthread_self() << " " << X << endl; \
00033 }
00034
00035 #define LOGL(Y,X) \
00036 if (g_iVerboseLevel >= Y && Log::log_out) \
00037 { \
00038 *Log::log_out << Log::localtime() << " " << pthread_self() << " " << X << endl; \
00039 }
00040
00041 #define LOG_CLOSE() \
00042 Log::close()
00043
00044 #define DB_AND_LOG(X) \
00045 { DB(X); LOG(X); }
00046
00047 #define DB_AND_LOGL(Y,X) \
00048 { DB(X); LOGL(Y,X); }
00049
00050 #define DB_AND_LOG_STAT(X) \
00051 DB_AND_LOG(#X << " = " << X)
00052
00053 #define DB_AND_LOGL_STAT(Y,X) \
00054 DB_AND_LOGL(Y,#X << " = " << X)
00055
00056 #define LOG_STAT(X) \
00057 LOG(#X << " = " << X)
00058
00059 #define LOGL_STAT(Y,X) \
00060 LOGL(Y,#X << " = " << X)
00061 #endif
00062 class Log
00063 {
00064 public:
00065 static ostream *log_out;
00066
00067 static void open(const std::string& _filename);
00068 static void close(void);
00069
00070 static std::string generate_filename(const std::string& _name = "output");
00071
00072 static std::string localtime(void);
00073 };
00074
00075 #endif // AS_LOG_H
00076