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 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00009 /*Produced by Andrew Hanushevsky for Stanford University under contract       */
00010 /*           DE-AC03-76-SFO0515 with the Deprtment of Energy                  */
00011 /******************************************************************************/
00012 
00013 //        $Id: XrdSysLogger.hh 32231 2010-02-05 18:24:46Z ganis $
00014 
00015 #include <stdlib.h>
00016 #ifndef WIN32
00017 #include <unistd.h>
00018 #include <string.h>
00019 #include <strings.h>
00020 #else
00021 #include <string.h>
00022 #include <io.h>
00023 #include "XrdSys/XrdWin32.hh"
00024 #endif
00025 
00026 #include "XrdSys/XrdSysPthread.hh"
00027 
00028 class XrdSysLogger
00029 {
00030 public:
00031          XrdSysLogger(int ErrFD=STDERR_FILENO, int xrotate=1);
00032 
00033         ~XrdSysLogger() {if (ePath) free(ePath);}
00034 
00035 // Bind allows you to bind standard error to a file with an optional periodic
00036 // closing and opening of the file.
00037 //
00038 int Bind(const char *path, int intsec=0);
00039 
00040 // Flush any pending output
00041 //
00042 void Flush() {fsync(eFD);}
00043 
00044 // originalFD() returns the base FD that we started with
00045 //
00046 int  originalFD() {return baseFD;}
00047 
00048 // Output data and optionally prefix with date/time
00049 //
00050 void Put(int iovcnt, struct iovec *iov);
00051 
00052 // Set log file keep value. A negative number means keep abs() files.
00053 //                          A positive number means keep no more than n bytes.
00054 //
00055 void setKeep(long long knum) {eKeep = knum;}
00056 
00057 // Set log file rotation on/off. Used by forked processes.
00058 //
00059 void setRotate(int onoff) {doLFR = onoff;}
00060 
00061 // Return formated date/time (tbuff must be atleast 24 characters)
00062 //
00063 int Time(char *tbuff);
00064 
00065 // traceBeg() obtains  the logger lock and returns a message header.
00066 // traceEnd() releases the logger lock and returns a newline
00067 //
00068 char *traceBeg() {Logger_Mutex.Lock(); Time(TBuff); return TBuff;}
00069 char  traceEnd() {Logger_Mutex.UnLock(); return '\n';}
00070 
00071 // xlogFD() returns the FD to be used by external programs as their STDERR.
00072 // A negative one indicates that no special FD is assigned.
00073 //
00074 int   xlogFD();
00075 
00076 private:
00077 
00078 XrdSysMutex Logger_Mutex;
00079 static int extLFD[4];
00080 long long  eKeep;
00081 char       TBuff[24];        // Trace header buffer
00082 int        eFD;
00083 int        baseFD;
00084 char      *ePath;
00085 char       Filesfx[8];
00086 time_t     eNTC;
00087 int        eInt;
00088 time_t     eNow;
00089 int        doLFR;
00090 
00091 void   putEmsg(char *msg, int msz);
00092 int    ReBind(int dorename=1);
00093 void   Trim();
00094 };
00095 #endif

Generated on Tue Jul 5 14:47:03 2011 for ROOT_528-00b_version by  doxygen 1.5.1