|
xrootd
|
00001 #ifndef XRC_DEBUG_H 00002 #define XRC_DEBUG_H 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d C l i e n t D e b u g . h h */ 00006 /* */ 00007 /* Author: Fabrizio Furano (INFN Padova, 2004) */ 00008 /* Adapted from TXNetFile (root.cern.ch) originally done by */ 00009 /* Alvise Dorigo, Fabrizio Furano */ 00010 /* INFN Padova, 2003 */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00034 // // 00035 // Singleton used to handle the debug level and the log output // 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 // ostringstream outs; // Declare an output string stream. 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
1.7.6.1