00001 #ifndef __XRDSYSTRACE_HH__
00002 #define __XRDSYSTRACE_HH__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <iostream>
00034 #include <sys/uio.h>
00035
00036 class XrdSysLogger;
00037
00038 #include "XrdSys/XrdSysPthread.hh"
00039
00040 namespace Xrd
00041 {
00042 enum Fmt {dec=0, hex};
00043 }
00044
00045 #define SYSTRACE(obj, usr, epn, txt, dbg) \
00046 obj Beg(usr, epn, txt) <<dbg <<obj End();
00047
00048 class XrdSysTrace
00049 {
00050 public:
00051
00052 XrdSysTrace& Beg(const char *usr=0, const char *epn=0, const char *txt=0);
00053
00054 XrdSysTrace *End() {return this;}
00055
00056 void SetLogger(XrdSysLogger *logp) {logP = logp;}
00057
00058 inline bool Tracing(int mask) {return (mask & What) != 0;}
00059
00060 int What;
00061
00062 XrdSysTrace& operator<<(bool val);
00063
00064 XrdSysTrace& operator<<( char val);
00065 XrdSysTrace& operator<<(const char *val);
00066 XrdSysTrace& operator<<(const std::string& val);
00067
00068 XrdSysTrace& operator<<(short val);
00069 XrdSysTrace& operator<<(int val);
00070 XrdSysTrace& operator<<(long val);
00071 XrdSysTrace& operator<<(long long val);
00072
00073 XrdSysTrace& operator<<(unsigned short val);
00074 XrdSysTrace& operator<<(unsigned int val);
00075 XrdSysTrace& operator<<(unsigned long val);
00076 XrdSysTrace& operator<<(unsigned long long val);
00077
00078 XrdSysTrace& operator<<(float val)
00079 {return Insert(static_cast<long double>(val));}
00080 XrdSysTrace& operator<<(double val)
00081 {return Insert(static_cast<long double>(val));}
00082 XrdSysTrace& operator<<(long double val)
00083 {return Insert(val);}
00084
00085 XrdSysTrace& operator<<(void* val);
00086
00087 XrdSysTrace& operator<<(Xrd::Fmt val)
00088 { if (val == Xrd::hex) doHex = true;
00089 else if (val == Xrd::dec) doHex = false;
00090 return *this;
00091 }
00092
00093 XrdSysTrace& operator<<(XrdSysTrace *stp);
00094
00095 XrdSysTrace(const char *pfx, XrdSysLogger *logp=0, int tf=0)
00096 : What(tf), logP(logp), iName(pfx), dPnt(0),
00097 dFree(txtMax), vPnt(1), doHex(false) {}
00098 ~XrdSysTrace() {}
00099
00100 private:
00101
00102 XrdSysTrace& Insert(long double val);
00103
00104 static const int iovMax = 16;
00105 static const int pfxMax = 256;
00106 static const int txtMax = 256;
00107
00108 XrdSysMutex myMutex;
00109 XrdSysLogger *logP;
00110 const char *iName;
00111 short dPnt;
00112 short dFree;
00113 short vPnt;
00114 bool doHex;
00115 struct iovec ioVec[iovMax];
00116 char pBuff[pfxMax];
00117 char dBuff[txtMax];
00118 };
00119 #endif