00001 #ifndef XRC_DEBUG_H
00002 #define XRC_DEBUG_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00034
00035
00036
00038
00039 #include <sstream>
00040 #include "XrdClient/XrdClientConst.hh"
00041 #include "XrdSys/XrdSysPthread.hh"
00042 #include "XrdClient/XrdClientEnv.hh"
00043 #include "XrdSys/XrdSysHeaders.hh"
00044 #include "XrdSys/XrdSysLogger.hh"
00045 #include "XrdSys/XrdSysError.hh"
00046
00047 using namespace std;
00048
00049 #define DebugLevel() XrdClientDebug::Instance()->GetDebugLevel()
00050 #define DebugSetLevel(l) XrdClientDebug::Instance()->SetLevel(l)
00051
00052 #define Info(lvl, where, what) { \
00053 XrdClientDebug::Instance()->Lock();\
00054 if (XrdClientDebug::Instance()->GetDebugLevel() >= lvl) {\
00055 ostringstream outs;\
00056 outs << where << ": " << what; \
00057 XrdClientDebug::Instance()->TraceStream((short)lvl, outs);\
00058 }\
00059 XrdClientDebug::Instance()->Unlock();\
00060 }
00061
00062 #define Error(where, what) { \
00063 ostringstream outs;\
00064 outs << where << ": " << what; \
00065 XrdClientDebug::Instance()->TraceStream((short)XrdClientDebug::kNODEBUG, outs);\
00066 }
00067
00068
00069 class XrdClientDebug {
00070 private:
00071 short fDbgLevel;
00072
00073 XrdSysLogger *fOucLog;
00074 XrdSysError *fOucErr;
00075
00076 static XrdClientDebug *fgInstance;
00077
00078 XrdSysRecMutex fMutex;
00079
00080 protected:
00081 XrdClientDebug();
00082 ~XrdClientDebug();
00083
00084 public:
00085
00086 enum {
00087 kNODEBUG = 0,
00088 kUSERDEBUG = 1,
00089 kHIDEBUG = 2,
00090 kDUMPDEBUG = 3
00091 };
00092
00093 short GetDebugLevel() {
00094 XrdSysMutexHelper m(fMutex);
00095 return fDbgLevel;
00096 }
00097
00098 static XrdClientDebug *Instance();
00099
00100 inline void SetLevel(int l) {
00101 XrdSysMutexHelper m(fMutex);
00102 fDbgLevel = l;
00103 }
00104
00105 inline void TraceStream(short DbgLvl, ostringstream &s) {
00106 XrdSysMutexHelper m(fMutex);
00107
00108 if (DbgLvl <= GetDebugLevel())
00109 fOucErr->Emsg("", s.str().c_str() );
00110
00111 s.str("");
00112 }
00113
00114
00115
00116 inline void TraceString(short DbgLvl, char * s) {
00117 XrdSysMutexHelper m(fMutex);
00118 if (DbgLvl <= GetDebugLevel())
00119 fOucErr->Emsg("", s);
00120 }
00121
00122 inline void Lock() { fMutex.Lock(); }
00123 inline void Unlock() { fMutex.UnLock(); }
00124
00125 };
00126 #endif