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 class XrdSysTrace
00046 {
00047 public:
00048
00049 XrdSysTrace& Beg(const char *usr=0, const char *epn=0, const char *txt=0);
00050
00051 void End();
00052
00053 void SetLogger(XrdSysLogger *logp) {logP = logp;}
00054
00055 inline bool Tracing(int mask) {return (mask & What) != 0;}
00056
00057 int What;
00058
00059 XrdSysTrace& operator<<(bool val);
00060
00061 XrdSysTrace& operator<<( char val);
00062 XrdSysTrace& operator<<(const char *val);
00063 XrdSysTrace& operator<<(const std::string& val);
00064
00065 XrdSysTrace& operator<<(short val);
00066 XrdSysTrace& operator<<(int val);
00067 XrdSysTrace& operator<<(long val);
00068 XrdSysTrace& operator<<(long long val);
00069
00070 XrdSysTrace& operator<<(unsigned short val);
00071 XrdSysTrace& operator<<(unsigned int val);
00072 XrdSysTrace& operator<<(unsigned long val);
00073 XrdSysTrace& operator<<(unsigned long long val);
00074
00075 XrdSysTrace& operator<<(float val)
00076 {return Insert(static_cast<long double>(val));}
00077 XrdSysTrace& operator<<(double val)
00078 {return Insert(static_cast<long double>(val));}
00079 XrdSysTrace& operator<<(long double val)
00080 {return Insert(val);}
00081
00082 XrdSysTrace& operator<<(void* val);
00083
00084 XrdSysTrace& operator<<(Xrd::Fmt val)
00085 { if (val == Xrd::hex) doHex = true;
00086 else if (val == Xrd::dec) doHex = false;
00087 return *this;
00088 }
00089
00090 XrdSysTrace(const char *pfx, XrdSysLogger *logp=0, int tf=0)
00091 : What(tf), logP(logp), iName(pfx), dPnt(0),
00092 dFree(txtMax), vPnt(1), doHex(false) {}
00093 ~XrdSysTrace() {}
00094
00095 private:
00096
00097 XrdSysTrace& Insert(long double val);
00098
00099 static const int iovMax = 16;
00100 static const int pfxMax = 256;
00101 static const int txtMax = 256;
00102
00103 XrdSysMutex myMutex;
00104 XrdSysLogger *logP;
00105 const char *iName;
00106 short dPnt;
00107 short dFree;
00108 short vPnt;
00109 bool doHex;
00110 struct iovec ioVec[iovMax];
00111 char pBuff[pfxMax];
00112 char dBuff[txtMax];
00113 };
00114 #endif