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