xrootd
Main Page
Namespaces
Classes
Files
File List
File Members
src
XrdClient
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>
40
#include "
XrdClient/XrdClientConst.hh
"
41
#include "
XrdSys/XrdSysPthread.hh
"
42
#include "
XrdClient/XrdClientEnv.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
69
class
XrdClientDebug
{
70
private
:
71
short
fDbgLevel
;
72
73
XrdSysLogger
*
fOucLog
;
74
XrdSysError
*
fOucErr
;
75
76
static
XrdClientDebug
*
fgInstance
;
77
78
XrdSysRecMutex
fMutex
;
79
80
protected
:
81
XrdClientDebug
();
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
Generated by
1.8.3.1