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 class XrdSysLogger
00046 {
00047 public:
00048          XrdSysLogger(int ErrFD=STDERR_FILENO, int xrotate=1);
00049 
00050         ~XrdSysLogger() {if (ePath) free(ePath);}
00051 
00052 // Bind allows you to bind standard error to a file with an optional periodic
00053 // closing and opening of the file.
00054 //
00055 int Bind(const char *path, int intsec=0);
00056 
00057 // Flush any pending output
00058 //
00059 void Flush() {fsync(eFD);}
00060 
00061 // originalFD() returns the base FD that we started with
00062 //
00063 int  originalFD() {return baseFD;}
00064 
00065 // Output data and optionally prefix with date/time
00066 //
00067 void Put(int iovcnt, struct iovec *iov);
00068 
00069 // Set log file keep value. A negative number means keep abs() files.
00070 //                          A positive number means keep no more than n bytes.
00071 //
00072 void setKeep(long long knum) {eKeep = knum;}
00073 
00074 // Set log file rotation on/off. Used by forked processes.
00075 //
00076 void setRotate(int onoff) {doLFR = onoff;}
00077 
00078 // Return formated date/time (tbuff must be atleast 24 characters)
00079 //
00080 int Time(char *tbuff);
00081 
00082 // traceBeg() obtains  the logger lock and returns a message header.
00083 // traceEnd() releases the logger lock and returns a newline
00084 //
00085 char *traceBeg() {Logger_Mutex.Lock(); Time(TBuff); return TBuff;}
00086 char  traceEnd() {Logger_Mutex.UnLock(); return '\n';}
00087 
00088 // xlogFD() returns the FD to be used by external programs as their STDERR.
00089 // A negative one indicates that no special FD is assigned.
00090 //
00091 int   xlogFD();
00092 
00093 private:
00094 
00095 XrdSysMutex Logger_Mutex;
00096 static int extLFD[4];
00097 long long  eKeep;
00098 char       TBuff[24];        // Trace header buffer
00099 int        eFD;
00100 int        baseFD;
00101 char      *ePath;
00102 char       Filesfx[8];
00103 time_t     eNTC;
00104 int        eInt;
00105 time_t     eNow;
00106 int        doLFR;
00107 
00108 void   putEmsg(char *msg, int msz);
00109 int    ReBind(int dorename=1);
00110 void   Trim();
00111 };
00112 #endif

Generated on 27 Jul 2013 for xrootd by  doxygen 1.4.7