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>
45#include "XrdSys/XrdSysError.hh"
46
47using namespace std;
48
49#define DebugLevel() XrdClientDebug::Instance()->GetDebugLevel()
50#define DebugSetLevel(l) XrdClientDebug::Instance()->SetLevel(l)
51
52#define Info(lvl, where, what) { \
53XrdClientDebug::Instance()->Lock();\
54if (XrdClientDebug::Instance()->GetDebugLevel() >= lvl) {\
55ostringstream outs;\
56outs << where << ": " << what; \
57XrdClientDebug::Instance()->TraceStream((short)lvl, outs);\
58}\
59XrdClientDebug::Instance()->Unlock();\
60}
61
62#define Error(where, what) { \
63ostringstream outs;\
64outs << where << ": " << what; \
65XrdClientDebug::Instance()->TraceStream((short)XrdClientDebug::kNODEBUG, outs);\
66}
67
68
70 private:
71 short fDbgLevel;
72
75
77
79
80 protected:
83
84 public:
85
86 enum {
90 kDUMPDEBUG = 3
91 };
92
93 short GetDebugLevel() {
95 return fDbgLevel;
96 }
97
99
100 inline void SetLevel(int l) {
102 fDbgLevel = l;
103 }
104
105 inline void TraceStream(short DbgLvl, ostringstream &s) {
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) {
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
Definition: XrdClientDebug.hh:69
XrdSysLogger * fOucLog
Definition: XrdClientDebug.hh:73
void Lock()
Definition: XrdClientDebug.hh:122
short GetDebugLevel()
Definition: XrdClientDebug.hh:93
static XrdClientDebug * Instance()
@ kNODEBUG
Definition: XrdClientDebug.hh:87
@ kUSERDEBUG
Definition: XrdClientDebug.hh:88
@ kDUMPDEBUG
Definition: XrdClientDebug.hh:90
@ kHIDEBUG
Definition: XrdClientDebug.hh:89
void TraceString(short DbgLvl, char *s)
Definition: XrdClientDebug.hh:116
XrdSysError * fOucErr
Definition: XrdClientDebug.hh:74
void SetLevel(int l)
Definition: XrdClientDebug.hh:100
XrdSysRecMutex fMutex
Definition: XrdClientDebug.hh:78
void TraceStream(short DbgLvl, ostringstream &s)
Definition: XrdClientDebug.hh:105
static XrdClientDebug * fgInstance
Definition: XrdClientDebug.hh:76
short fDbgLevel
Definition: XrdClientDebug.hh:71
void Unlock()
Definition: XrdClientDebug.hh:123
Definition: XrdSysError.hh:90
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysLogger.hh:53
Definition: XrdSysPthread.hh:261
void Lock()
Definition: XrdSysPthread.hh:220
void UnLock()
Definition: XrdSysPthread.hh:222
Definition: XrdSysPthread.hh:240