xrootd
XrdSysTrace.hh
Go to the documentation of this file.
1 #ifndef __XRDSYSTRACE_HH__
2 #define __XRDSYSTRACE_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d S y s T r a c e . h h */
6 /* */
7 /* (c) 2016 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
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 
33 #include <iostream>
34 #include <sys/uio.h>
35 
36 class XrdSysLogger;
37 
38 #include "XrdSys/XrdSysPthread.hh"
39 
40 namespace Xrd
41 {
42 enum Fmt {dec=0, hex};
43 }
44 
45 #define SYSTRACE(obj, usr, epn, txt, dbg) \
46  obj Beg(usr, epn, txt) <<dbg <<obj End();
47 
49 {
50 public:
51 
52 XrdSysTrace& Beg(const char *usr=0, const char *epn=0, const char *txt=0);
53 
54 XrdSysTrace *End() {return this;}
55 
56 void SetLogger(XrdSysLogger *logp) {logP = logp;}
57 
58 inline bool Tracing(int mask) {return (mask & What) != 0;}
59 
60  int What;
61 
62 XrdSysTrace& operator<<(bool val);
63 
64 XrdSysTrace& operator<<( char val);
65 XrdSysTrace& operator<<(const char *val);
66  XrdSysTrace& operator<<(const std::string& val);
67 
68 XrdSysTrace& operator<<(short val);
69 XrdSysTrace& operator<<(int val);
70 XrdSysTrace& operator<<(long val);
71 XrdSysTrace& operator<<(long long val);
72 
73 XrdSysTrace& operator<<(unsigned short val);
74 XrdSysTrace& operator<<(unsigned int val);
75 XrdSysTrace& operator<<(unsigned long val);
76 XrdSysTrace& operator<<(unsigned long long val);
77 
79  {return Insert(static_cast<long double>(val));}
80 XrdSysTrace& operator<<(double val)
81  {return Insert(static_cast<long double>(val));}
82 XrdSysTrace& operator<<(long double val)
83  {return Insert(val);}
84 
85 XrdSysTrace& operator<<(void* val);
86 
88  { if (val == Xrd::hex) doHex = true;
89  else if (val == Xrd::dec) doHex = false;
90  return *this;
91  }
92 
94 
95  XrdSysTrace(const char *pfx, XrdSysLogger *logp=0, int tf=0)
96  : What(tf), logP(logp), iName(pfx), dPnt(0),
97  dFree(txtMax), vPnt(1), doHex(false) {}
99 
100 private:
101 
102 XrdSysTrace& Insert(long double val);
103 
104 static const int iovMax = 16;
105 static const int pfxMax = 256;
106 static const int txtMax = 256;
107 
110 const char *iName;
111 short dPnt;
112 short dFree;
113 short vPnt;
114 bool doHex;
115 struct iovec ioVec[iovMax];
116 char pBuff[pfxMax];
117 char dBuff[txtMax];
118 };
119 #endif
XrdSysTrace::logP
XrdSysLogger * logP
Definition: XrdSysTrace.hh:109
XrdSysTrace::XrdSysTrace
XrdSysTrace(const char *pfx, XrdSysLogger *logp=0, int tf=0)
Definition: XrdSysTrace.hh:95
XrdSysTrace::operator<<
XrdSysTrace & operator<<(Xrd::Fmt val)
Definition: XrdSysTrace.hh:87
XrdSysTrace::ioVec
struct iovec ioVec[iovMax]
Definition: XrdSysTrace.hh:115
XrdSysTrace::pfxMax
static const int pfxMax
Definition: XrdSysTrace.hh:105
XrdSysMutex
Definition: XrdSysPthread.hh:165
XrdSysTrace::~XrdSysTrace
~XrdSysTrace()
Definition: XrdSysTrace.hh:98
XrdSysTrace::vPnt
short vPnt
Definition: XrdSysTrace.hh:113
XrdSysPthread.hh
XrdSysTrace::Insert
XrdSysTrace & Insert(long double val)
XrdSysTrace::SetLogger
void SetLogger(XrdSysLogger *logp)
Definition: XrdSysTrace.hh:56
Xrd::hex
@ hex
Definition: XrdSysTrace.hh:42
XrdSysTrace::myMutex
XrdSysMutex myMutex
Definition: XrdSysTrace.hh:108
Xrd::dec
@ dec
Definition: XrdSysTrace.hh:42
XrdSysTrace::Beg
XrdSysTrace & Beg(const char *usr=0, const char *epn=0, const char *txt=0)
XrdSysTrace::dFree
short dFree
Definition: XrdSysTrace.hh:112
Xrd::Fmt
Fmt
Definition: XrdSysTrace.hh:42
XrdSysTrace::pBuff
char pBuff[pfxMax]
Definition: XrdSysTrace.hh:116
XrdSysTrace::operator<<
XrdSysTrace & operator<<(double val)
Definition: XrdSysTrace.hh:80
XrdSysTrace::End
XrdSysTrace * End()
Definition: XrdSysTrace.hh:54
XrdSysTrace::operator<<
XrdSysTrace & operator<<(bool val)
XrdSysLogger
Definition: XrdSysLogger.hh:52
Xrd
Definition: XrdSysTrace.hh:40
XrdSysTrace::What
int What
Definition: XrdSysTrace.hh:60
XrdSysTrace::iovMax
static const int iovMax
Definition: XrdSysTrace.hh:104
XrdSysTrace::dPnt
short dPnt
Definition: XrdSysTrace.hh:111
XrdSysTrace::operator<<
XrdSysTrace & operator<<(float val)
Definition: XrdSysTrace.hh:78
XrdSysTrace::txtMax
static const int txtMax
Definition: XrdSysTrace.hh:106
XrdSysTrace::doHex
bool doHex
Definition: XrdSysTrace.hh:114
XrdSysTrace::iName
const char * iName
Definition: XrdSysTrace.hh:110
XrdSysTrace
Definition: XrdSysTrace.hh:48
XrdSysTrace::operator<<
XrdSysTrace & operator<<(long double val)
Definition: XrdSysTrace.hh:82
XrdSysTrace::Tracing
bool Tracing(int mask)
Definition: XrdSysTrace.hh:58
XrdSysTrace::dBuff
char dBuff[txtMax]
Definition: XrdSysTrace.hh:117