Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-08 10:33:34

0001 #ifndef __XRDSYSTRACE_HH__
0002 #define __XRDSYSTRACE_HH__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                        X r d S y s T r a c e . h h                         */
0006 /*                                                                            */
0007 /* (c) 2016 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*                            All Rights Reserved                             */
0009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0011 /*                                                                            */
0012 /* This file is part of the XRootD software suite.                            */
0013 /*                                                                            */
0014 /* XRootD is free software: you can redistribute it and/or modify it under    */
0015 /* the terms of the GNU Lesser General Public License as published by the     */
0016 /* Free Software Foundation, either version 3 of the License, or (at your     */
0017 /* option) any later version.                                                 */
0018 /*                                                                            */
0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0022 /* License for more details.                                                  */
0023 /*                                                                            */
0024 /* You should have received a copy of the GNU Lesser General Public License   */
0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0027 /*                                                                            */
0028 /* The copyright holder's institutional names and contributor's names may not */
0029 /* be used to endorse or promote products derived from this software without  */
0030 /* specific prior written permission of the institution or contributor.       */
0031 /******************************************************************************/
0032 
0033 #include <iostream>
0034 #include <sys/uio.h>
0035 
0036 class XrdSysLogger;
0037 
0038 #include "XrdSys/XrdSysPthread.hh"
0039 
0040 namespace Xrd
0041 {
0042 enum Fmt {dec=0, hex=2, hex1=3, oct=4, oct1=5};
0043 }
0044 
0045 #define SYSTRACE(obj, usr, epn, txt, dbg) \
0046         obj Beg(usr, epn, txt) <<dbg <<obj End();
0047 
0048 class XrdSysTrace
0049 {
0050 public:
0051 
0052 XrdSysTrace& Beg(const char *usr=0, const char *epn=0, const char *txt=0);
0053 
0054 XrdSysTrace *End() {return this;}
0055 
0056 void         SetLogger(XrdSysLogger *logp);
0057 
0058 typedef void (*msgCB_t)(const char *tid, const char *msg, bool dbgmsg);
0059 
0060 void         SetLogger(msgCB_t cbP);
0061 
0062 inline bool  Tracing(int mask) {return (mask & What) != 0;}
0063 
0064        int   What;
0065 
0066 XrdSysTrace& operator<<(bool        val);
0067 
0068 XrdSysTrace& operator<<(      char  val);
0069 XrdSysTrace& operator<<(const char *val);
0070    XrdSysTrace& operator<<(const std::string& val);
0071 
0072 XrdSysTrace& operator<<(short       val);
0073 XrdSysTrace& operator<<(int         val);
0074 XrdSysTrace& operator<<(long        val);
0075 XrdSysTrace& operator<<(long long   val);
0076 
0077 XrdSysTrace& operator<<(unsigned short     val);
0078 XrdSysTrace& operator<<(unsigned int       val);
0079 XrdSysTrace& operator<<(unsigned long      val);
0080 XrdSysTrace& operator<<(unsigned long long val);
0081 
0082 XrdSysTrace& operator<<(float       val)
0083                        {return Insert(static_cast<long double>(val));}
0084 XrdSysTrace& operator<<(double      val)
0085                        {return Insert(static_cast<long double>(val));}
0086 XrdSysTrace& operator<<(long double val)
0087                        {return Insert(val);}
0088 
0089 XrdSysTrace& operator<<(void* val);
0090 
0091 XrdSysTrace& operator<<(Xrd::Fmt val) {doFmt = val; return *this;}
0092 
0093 XrdSysTrace& operator<<(XrdSysTrace *stp);
0094 
0095              XrdSysTrace(const char *pfx, XrdSysLogger *logp=0, int tf=0)
0096                         : What(tf), logP(logp), iName(pfx), dPnt(0),
0097                           dFree(txtMax), vPnt(1), doFmt(Xrd::dec) {}
0098             ~XrdSysTrace() {}
0099 
0100 private:
0101 
0102 XrdSysTrace& Insert(long double val);
0103 
0104 static const int iovMax =  16;
0105 static const int pfxMax = 256;
0106 static const int txtMax = 256;
0107 
0108 static const int doOne  =0x01;
0109 
0110 XrdSysMutex      myMutex;
0111 XrdSysLogger    *logP;
0112 const char      *iName;
0113 short            dPnt;
0114 short            dFree;
0115 short            vPnt;
0116 Xrd::Fmt         doFmt;
0117 struct iovec     ioVec[iovMax];
0118 char             pBuff[pfxMax];
0119 char             dBuff[txtMax];
0120 };
0121 #endif