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, hex1};
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);
57 
58 typedef void (*msgCB_t)(const char *tid, const char *msg, bool dbgmsg);
59 
60 void SetLogger(msgCB_t cbP);
61 
62 inline bool Tracing(int mask) {return (mask & What) != 0;}
63 
64  int What;
65 
67 
68 XrdSysTrace& operator<<( char val);
69 XrdSysTrace& operator<<(const char *val);
70  XrdSysTrace& operator<<(const std::string& val);
71 
72 XrdSysTrace& operator<<(short val);
75 XrdSysTrace& operator<<(long long val);
76 
77 XrdSysTrace& operator<<(unsigned short val);
78 XrdSysTrace& operator<<(unsigned int val);
79 XrdSysTrace& operator<<(unsigned long val);
80 XrdSysTrace& operator<<(unsigned long long val);
81 
83  {return Insert(static_cast<long double>(val));}
84 XrdSysTrace& operator<<(double val)
85  {return Insert(static_cast<long double>(val));}
86 XrdSysTrace& operator<<(long double val)
87  {return Insert(val);}
88 
89 XrdSysTrace& operator<<(void* val);
90 
92  { if (val == Xrd::hex) doHex = 1;
93  else if (val == Xrd::hex1) doHex = -1;
94  else if (val == Xrd::dec) doHex = 0;
95  return *this;
96  }
97 
99 
100  XrdSysTrace(const char *pfx, XrdSysLogger *logp=0, int tf=0)
101  : What(tf), logP(logp), iName(pfx), dPnt(0),
102  dFree(txtMax), vPnt(1), doHex(0) {}
104 
105 private:
106 
107 XrdSysTrace& Insert(long double val);
108 
109 static const int iovMax = 16;
110 static const int pfxMax = 256;
111 static const int txtMax = 256;
112 
115 const char *iName;
116 short dPnt;
117 short dFree;
118 short vPnt;
119 signed char doHex;
120 struct iovec ioVec[iovMax];
121 char pBuff[pfxMax];
122 char dBuff[txtMax];
123 };
124 #endif
Definition: XrdSysLogger.hh:53
Definition: XrdSysPthread.hh:165
Definition: XrdSysTrace.hh:49
XrdSysTrace(const char *pfx, XrdSysLogger *logp=0, int tf=0)
Definition: XrdSysTrace.hh:100
XrdSysTrace & operator<<(const std::string &val)
const char * iName
Definition: XrdSysTrace.hh:115
XrdSysTrace * End()
Definition: XrdSysTrace.hh:54
XrdSysTrace & operator<<(const char *val)
XrdSysTrace & operator<<(long long val)
XrdSysTrace & operator<<(unsigned long long val)
XrdSysTrace & operator<<(bool val)
XrdSysTrace & Insert(long double val)
XrdSysTrace & operator<<(unsigned int val)
static const int pfxMax
Definition: XrdSysTrace.hh:110
short vPnt
Definition: XrdSysTrace.hh:118
XrdSysTrace & operator<<(unsigned long val)
XrdSysTrace & operator<<(void *val)
signed char doHex
Definition: XrdSysTrace.hh:119
short dFree
Definition: XrdSysTrace.hh:117
int What
Definition: XrdSysTrace.hh:64
void(* msgCB_t)(const char *tid, const char *msg, bool dbgmsg)
Definition: XrdSysTrace.hh:58
XrdSysTrace & operator<<(short val)
void SetLogger(msgCB_t cbP)
char pBuff[pfxMax]
Definition: XrdSysTrace.hh:121
XrdSysMutex myMutex
Definition: XrdSysTrace.hh:113
XrdSysTrace & operator<<(float val)
Definition: XrdSysTrace.hh:82
XrdSysTrace & operator<<(double val)
Definition: XrdSysTrace.hh:84
~XrdSysTrace()
Definition: XrdSysTrace.hh:103
XrdSysTrace & operator<<(int val)
char dBuff[txtMax]
Definition: XrdSysTrace.hh:122
XrdSysTrace & operator<<(unsigned short val)
XrdSysTrace & operator<<(char val)
XrdSysTrace & operator<<(long double val)
Definition: XrdSysTrace.hh:86
short dPnt
Definition: XrdSysTrace.hh:116
struct iovec ioVec[iovMax]
Definition: XrdSysTrace.hh:120
XrdSysTrace & Beg(const char *usr=0, const char *epn=0, const char *txt=0)
XrdSysLogger * logP
Definition: XrdSysTrace.hh:114
XrdSysTrace & operator<<(XrdSysTrace *stp)
static const int txtMax
Definition: XrdSysTrace.hh:111
XrdSysTrace & operator<<(long val)
XrdSysTrace & operator<<(Xrd::Fmt val)
Definition: XrdSysTrace.hh:91
void SetLogger(XrdSysLogger *logp)
bool Tracing(int mask)
Definition: XrdSysTrace.hh:62
static const int iovMax
Definition: XrdSysTrace.hh:109
Definition: XrdSysTrace.hh:41
Fmt
Definition: XrdSysTrace.hh:42
@ dec
Definition: XrdSysTrace.hh:42
@ hex1
Definition: XrdSysTrace.hh:42
@ hex
Definition: XrdSysTrace.hh:42