xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 
46 {
47 public:
48 
49 XrdSysTrace& Beg(const char *usr=0, const char *epn=0, const char *txt=0);
50 
51 void End();
52 
53 void SetLogger(XrdSysLogger *logp) {logP = logp;}
54 
55 inline bool Tracing(int mask) {return (mask & What) != 0;}
56 
57  int What;
58 
59 XrdSysTrace& operator<<(bool val);
60 
61 XrdSysTrace& operator<<( char val);
62 XrdSysTrace& operator<<(const char *val);
63  XrdSysTrace& operator<<(const std::string& val);
64 
65 XrdSysTrace& operator<<(short val);
66 XrdSysTrace& operator<<(int val);
67 XrdSysTrace& operator<<(long val);
68 XrdSysTrace& operator<<(long long val);
69 
70 XrdSysTrace& operator<<(unsigned short val);
71 XrdSysTrace& operator<<(unsigned int val);
72 XrdSysTrace& operator<<(unsigned long val);
73 XrdSysTrace& operator<<(unsigned long long val);
74 
76  {return Insert(static_cast<long double>(val));}
77 XrdSysTrace& operator<<(double val)
78  {return Insert(static_cast<long double>(val));}
79 XrdSysTrace& operator<<(long double val)
80  {return Insert(val);}
81 
82 XrdSysTrace& operator<<(void* val);
83 
85  { if (val == Xrd::hex) doHex = true;
86  else if (val == Xrd::dec) doHex = false;
87  return *this;
88  }
89 
90  XrdSysTrace(const char *pfx, XrdSysLogger *logp=0, int tf=0)
91  : What(tf), logP(logp), iName(pfx), dPnt(0),
92  dFree(txtMax), vPnt(1), doHex(false) {}
94 
95 private:
96 
97 XrdSysTrace& Insert(long double val);
98 
99 static const int iovMax = 16;
100 static const int pfxMax = 256;
101 static const int txtMax = 256;
102 
105 const char *iName;
106 short dPnt;
107 short dFree;
108 short vPnt;
109 bool doHex;
110 struct iovec ioVec[iovMax];
111 char pBuff[pfxMax];
112 char dBuff[txtMax];
113 };
114 #endif
~XrdSysTrace()
Definition: XrdSysTrace.hh:93
short vPnt
Definition: XrdSysTrace.hh:108
XrdSysTrace & Insert(long double val)
XrdSysLogger * logP
Definition: XrdSysTrace.hh:104
void SetLogger(XrdSysLogger *logp)
Definition: XrdSysTrace.hh:53
Definition: XrdSysTrace.hh:45
XrdSysMutex myMutex
Definition: XrdSysTrace.hh:103
Definition: XrdSysPthread.hh:165
XrdSysTrace & Beg(const char *usr=0, const char *epn=0, const char *txt=0)
short dFree
Definition: XrdSysTrace.hh:107
short dPnt
Definition: XrdSysTrace.hh:106
char pBuff[pfxMax]
Definition: XrdSysTrace.hh:111
XrdSysTrace & operator<<(double val)
Definition: XrdSysTrace.hh:77
Definition: XrdSysTrace.hh:42
Definition: XrdSysLogger.hh:52
XrdSysTrace & operator<<(bool val)
XrdSysTrace & operator<<(float val)
Definition: XrdSysTrace.hh:75
Definition: XrdSysTrace.hh:42
Fmt
Definition: XrdSysTrace.hh:42
int What
Definition: XrdSysTrace.hh:57
const char * iName
Definition: XrdSysTrace.hh:105
char dBuff[txtMax]
Definition: XrdSysTrace.hh:112
static const int iovMax
Definition: XrdSysTrace.hh:99
static const int txtMax
Definition: XrdSysTrace.hh:101
XrdSysTrace & operator<<(Xrd::Fmt val)
Definition: XrdSysTrace.hh:84
bool Tracing(int mask)
Definition: XrdSysTrace.hh:55
struct iovec ioVec[iovMax]
Definition: XrdSysTrace.hh:110
static const int pfxMax
Definition: XrdSysTrace.hh:100
XrdSysTrace & operator<<(long double val)
Definition: XrdSysTrace.hh:79
bool doHex
Definition: XrdSysTrace.hh:109
XrdSysTrace(const char *pfx, XrdSysLogger *logp=0, int tf=0)
Definition: XrdSysTrace.hh:90