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=2, hex1=3, oct=4, oct1=5};
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 
66 XrdSysTrace& operator<<(bool val);
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);
73 XrdSysTrace& operator<<(int val);
74 XrdSysTrace& operator<<(long 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 
91 XrdSysTrace& operator<<(Xrd::Fmt val) {doFmt = val; return *this;}
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), doFmt(Xrd::dec) {}
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 
108 static const int doOne =0x01;
109 
110 XrdSysMutex myMutex;
111 XrdSysLogger *logP;
112 const char *iName;
113 short dPnt;
114 short dFree;
115 short vPnt;
116 Xrd::Fmt doFmt;
117 struct iovec ioVec[iovMax];
118 char pBuff[pfxMax];
119 char dBuff[txtMax];
120 };
121 #endif
XrdSysTrace(const char *pfx, XrdSysLogger *logp=0, int tf=0)
Definition: XrdSysTrace.hh:95
XrdSysTrace * End()
Definition: XrdSysTrace.hh:54
XrdSysTrace & Beg(const char *usr=0, const char *epn=0, const char *txt=0)
Definition: XrdSysTrace.cc:73
void(* msgCB_t)(const char *tid, const char *msg, bool dbgmsg)
Definition: XrdSysTrace.hh:58
XrdSysTrace & operator<<(bool val)
Definition: XrdSysTrace.cc:145
XrdSysTrace & operator<<(float val)
Definition: XrdSysTrace.hh:82
XrdSysTrace & operator<<(double val)
Definition: XrdSysTrace.hh:84
XrdSysTrace & operator<<(long double val)
Definition: XrdSysTrace.hh:86
XrdSysTrace & operator<<(Xrd::Fmt val)
Definition: XrdSysTrace.hh:91
void SetLogger(XrdSysLogger *logp)
Definition: XrdSysTrace.cc:65
bool Tracing(int mask)
Definition: XrdSysTrace.hh:62
@ oct
Definition: XrdSysTrace.hh:42
@ dec
Definition: XrdSysTrace.hh:42
@ hex1
Definition: XrdSysTrace.hh:42
@ oct1
Definition: XrdSysTrace.hh:42
@ hex
Definition: XrdSysTrace.hh:42