XrdSysLogger.hh

Go to the documentation of this file.
00001 #ifndef __SYS_LOGGER_H__
00002 #define __SYS_LOGGER_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                       X r d S y s L o g g e r . h h                        */
00006 /*                                                                            */
00007 /*(c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University   */
00008 /*Produced by Andrew Hanushevsky for Stanford University under contract       */
00009 /*           DE-AC02-76-SFO0515 with the Deprtment of Energy                  */
00010 /*                                                                            */
00011 /* This file is part of the XRootD software suite.                            */
00012 /*                                                                            */
00013 /* XRootD is free software: you can redistribute it and/or modify it under    */
00014 /* the terms of the GNU Lesser General Public License as published by the     */
00015 /* Free Software Foundation, either version 3 of the License, or (at your     */
00016 /* option) any later version.                                                 */
00017 /*                                                                            */
00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00020 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00021 /* License for more details.                                                  */
00022 /*                                                                            */
00023 /* You should have received a copy of the GNU Lesser General Public License   */
00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00025 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00026 /*                                                                            */
00027 /* The copyright holder's institutional names and contributor's names may not */
00028 /* be used to endorse or promote products derived from this software without  */
00029 /* specific prior written permission of the institution or contributor.       */
00030 /******************************************************************************/
00031 
00032 #include <stdlib.h>
00033 #ifndef WIN32
00034 #include <unistd.h>
00035 #include <string.h>
00036 #include <strings.h>
00037 #else
00038 #include <string.h>
00039 #include <io.h>
00040 #include "XrdSys/XrdWin32.hh"
00041 #endif
00042 
00043 #include "XrdSys/XrdSysPthread.hh"
00044 
00045 //-----------------------------------------------------------------------------
00048 //-----------------------------------------------------------------------------
00049 
00050 class XrdSysLogger
00051 {
00052 public:
00053 
00054 //-----------------------------------------------------------------------------
00061 //-----------------------------------------------------------------------------
00062 
00063          XrdSysLogger(int ErrFD=STDERR_FILENO, int xrotate=1);
00064 
00065 //-----------------------------------------------------------------------------
00067 //-----------------------------------------------------------------------------
00068 
00069         ~XrdSysLogger() {if (ePath) free(ePath);}
00070 
00071 //-----------------------------------------------------------------------------
00075 //-----------------------------------------------------------------------------
00076 
00077 void  AddMsg(const char *msg);
00078 
00079 //-----------------------------------------------------------------------------
00083 //-----------------------------------------------------------------------------
00084 
00085 class Task
00086 {
00087 public:
00088 friend class XrdSysLogger;
00089 
00090 virtual void  Ring() = 0; 
00091 
00092 inline  Task *Next() {return next;}
00093 
00094               Task() : next(0) {}
00095 virtual      ~Task() {}
00096 
00097 private:
00098 Task *next;
00099 };
00100 
00101 void  AtMidnight(Task *mnTask);
00102 
00103 //-----------------------------------------------------------------------------
00125 //-----------------------------------------------------------------------------
00126 
00127 static const int onFifo = (int)0x80000000;
00128 
00129 int Bind(const char *path, int lfh=0);
00130 
00131 //-----------------------------------------------------------------------------
00133 //-----------------------------------------------------------------------------
00134 
00135 void Flush() {fsync(eFD);}
00136 
00137 //-----------------------------------------------------------------------------
00141 //-----------------------------------------------------------------------------
00142 
00143 int  originalFD() {return baseFD;}
00144 
00145 //-----------------------------------------------------------------------------
00154 //-----------------------------------------------------------------------------
00155 
00156 int  ParseKeep(const char *arg);
00157 
00158 //-----------------------------------------------------------------------------
00164 //-----------------------------------------------------------------------------
00165 
00166 void Put(int iovcnt, struct iovec *iov);
00167 
00168 //-----------------------------------------------------------------------------
00170 //-----------------------------------------------------------------------------
00171 
00172 static
00173 void setForwarding(bool onoff) {doForward = onoff;}
00174 
00175 //-----------------------------------------------------------------------------
00177 //-----------------------------------------------------------------------------
00178 
00179 void setHiRes() {hiRes = true;}
00180 
00181 //-----------------------------------------------------------------------------
00186 //-----------------------------------------------------------------------------
00187 
00188 void setKeep(long long knum) {eKeep = knum;}
00189 
00190 //-----------------------------------------------------------------------------
00195 //-----------------------------------------------------------------------------
00196 
00197 void setRotate(int onoff) {doLFR = onoff;}
00198 
00199 //-----------------------------------------------------------------------------
00204 //-----------------------------------------------------------------------------
00205 
00206 char *traceBeg() {Logger_Mutex.Lock(); Time(TBuff); return TBuff;}
00207 
00208 //-----------------------------------------------------------------------------
00213 //-----------------------------------------------------------------------------
00214 
00215 char  traceEnd() {Logger_Mutex.UnLock(); return '\n';}
00216 
00217 //-----------------------------------------------------------------------------
00221 //-----------------------------------------------------------------------------
00222 
00223 const char *xlogFN() {return (ePath ? ePath : "stderr");}
00224 
00225 //-----------------------------------------------------------------------------
00228 //-----------------------------------------------------------------------------
00229 
00230 void        zHandler();
00231 
00232 private:
00233 int         FifoMake();
00234 void        FifoWait();
00235 int         Time(char *tbuff);
00236 static int  TimeStamp(struct timeval &tVal, unsigned long tID,
00237                       char *tbuff, int tbsz, bool hires);
00238 
00239 struct mmMsg
00240       {mmMsg *next;
00241        int    mlen;
00242        char  *msg;
00243       };
00244 mmMsg     *msgList;
00245 Task      *taskQ;
00246 XrdSysMutex Logger_Mutex;
00247 long long  eKeep;
00248 char       TBuff[32];        // Trace header buffer
00249 int        eFD;
00250 int        baseFD;
00251 char      *ePath;
00252 char       Filesfx[8];
00253 int        eInt;
00254 int        reserved1;
00255 char      *fifoFN;
00256 bool       hiRes;
00257 bool       doLFR;
00258 pthread_t  lfhTID;
00259 
00260 static bool doForward;
00261 
00262 void   putEmsg(char *msg, int msz);
00263 int    ReBind(int dorename=1);
00264 void   Trim();
00265 };
00266 #endif

Generated on 13 Mar 2017 for xrootd by  doxygen 1.4.7