xrootd
XrdClientDebug.hh
Go to the documentation of this file.
1 #ifndef XRC_DEBUG_H
2 #define XRC_DEBUG_H
3 /******************************************************************************/
4 /* */
5 /* X r d C l i e n t D e b u g . h h */
6 /* */
7 /* Author: Fabrizio Furano (INFN Padova, 2004) */
8 /* Adapted from TXNetFile (root.cern.ch) originally done by */
9 /* Alvise Dorigo, Fabrizio Furano */
10 /* INFN Padova, 2003 */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
34 // //
35 // Singleton used to handle the debug level and the log output //
36 // //
38 
39 #include <sstream>
41 #include "XrdSys/XrdSysPthread.hh"
43 #include "XrdSys/XrdSysHeaders.hh"
44 #include "XrdSys/XrdSysLogger.hh"
45 #include "XrdSys/XrdSysError.hh"
46 
47 using namespace std;
48 
49 #define DebugLevel() XrdClientDebug::Instance()->GetDebugLevel()
50 #define DebugSetLevel(l) XrdClientDebug::Instance()->SetLevel(l)
51 
52 #define Info(lvl, where, what) { \
53 XrdClientDebug::Instance()->Lock();\
54 if (XrdClientDebug::Instance()->GetDebugLevel() >= lvl) {\
55 ostringstream outs;\
56 outs << where << ": " << what; \
57 XrdClientDebug::Instance()->TraceStream((short)lvl, outs);\
58 }\
59 XrdClientDebug::Instance()->Unlock();\
60 }
61 
62 #define Error(where, what) { \
63 ostringstream outs;\
64 outs << where << ": " << what; \
65 XrdClientDebug::Instance()->TraceStream((short)XrdClientDebug::kNODEBUG, outs);\
66 }
67 
68 
70  private:
71  short fDbgLevel;
72 
75 
77 
79 
80  protected:
82  ~XrdClientDebug();
83 
84  public:
85 
86  enum {
87  kNODEBUG = 0,
88  kUSERDEBUG = 1,
89  kHIDEBUG = 2,
90  kDUMPDEBUG = 3
91  };
92 
93  short GetDebugLevel() {
94  XrdSysMutexHelper m(fMutex);
95  return fDbgLevel;
96  }
97 
98  static XrdClientDebug *Instance();
99 
100  inline void SetLevel(int l) {
101  XrdSysMutexHelper m(fMutex);
102  fDbgLevel = l;
103  }
104 
105  inline void TraceStream(short DbgLvl, ostringstream &s) {
106  XrdSysMutexHelper m(fMutex);
107 
108  if (DbgLvl <= GetDebugLevel())
109  fOucErr->Emsg("", s.str().c_str() );
110 
111  s.str("");
112  }
113 
114  // ostringstream outs; // Declare an output string stream.
115 
116  inline void TraceString(short DbgLvl, char * s) {
117  XrdSysMutexHelper m(fMutex);
118  if (DbgLvl <= GetDebugLevel())
119  fOucErr->Emsg("", s);
120  }
121 
122  inline void Lock() { fMutex.Lock(); }
123  inline void Unlock() { fMutex.UnLock(); }
124 
125 };
126 #endif
void Unlock()
Definition: XrdClientDebug.hh:123
void TraceString(short DbgLvl, char *s)
Definition: XrdClientDebug.hh:116
Definition: XrdSysPthread.hh:239
void TraceStream(short DbgLvl, ostringstream &s)
Definition: XrdClientDebug.hh:105
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.hh:89
XrdSysLogger * fOucLog
Definition: XrdClientDebug.hh:73
short fDbgLevel
Definition: XrdClientDebug.hh:71
XrdSysError * fOucErr
Definition: XrdClientDebug.hh:74
static XrdClientDebug * fgInstance
Definition: XrdClientDebug.hh:76
void Lock()
Definition: XrdClientDebug.hh:122
Definition: XrdSysLogger.hh:52
void Lock()
Definition: XrdSysPthread.hh:220
Definition: XrdClientDebug.hh:69
XrdSysRecMutex fMutex
Definition: XrdClientDebug.hh:78
short GetDebugLevel()
Definition: XrdClientDebug.hh:93
void UnLock()
Definition: XrdSysPthread.hh:222
Definition: XrdSysPthread.hh:260
void SetLevel(int l)
Definition: XrdClientDebug.hh:100