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