xrootd
XrdSysLogger.hh
Go to the documentation of this file.
1 #ifndef __SYS_LOGGER_H__
2 #define __SYS_LOGGER_H__
3 /******************************************************************************/
4 /* */
5 /* X r d S y s L o g g e r . h h */
6 /* */
7 /*(c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */
9 /*Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC03-76-SFO0515 with the Deprtment of Energy */
11 /******************************************************************************/
12 
13 // $Id$
14 
15 #include <stdlib.h>
16 #ifndef WIN32
17 #include <unistd.h>
18 #include <string.h>
19 #include <strings.h>
20 #else
21 #include <string.h>
22 #include <io.h>
23 #include "XrdSys/XrdWin32.hh"
24 #endif
25 
26 #include "XrdSys/XrdSysPthread.hh"
27 
29 {
30 public:
31  XrdSysLogger(int ErrFD=STDERR_FILENO, int xrotate=1);
32 
33  ~XrdSysLogger() {if (ePath) free(ePath);}
34 
35 // Bind allows you to bind standard error to a file with an optional periodic
36 // closing and opening of the file.
37 //
38 int Bind(const char *path, int intsec=0);
39 
40 // Flush any pending output
41 //
42 void Flush() {fsync(eFD);}
43 
44 // originalFD() returns the base FD that we started with
45 //
46 int originalFD() {return baseFD;}
47 
48 // Output data and optionally prefix with date/time
49 //
50 void Put(int iovcnt, struct iovec *iov);
51 
52 // Set log file keep value. A negative number means keep abs() files.
53 // A positive number means keep no more than n bytes.
54 //
55 void setKeep(long long knum) {eKeep = knum;}
56 
57 // Set log file rotation on/off. Used by forked processes.
58 //
59 void setRotate(int onoff) {doLFR = onoff;}
60 
61 // Return formated date/time (tbuff must be atleast 24 characters)
62 //
63 int Time(char *tbuff);
64 
65 // traceBeg() obtains the logger lock and returns a message header.
66 // traceEnd() releases the logger lock and returns a newline
67 //
68 char *traceBeg() {Logger_Mutex.Lock(); Time(TBuff); return TBuff;}
69 char traceEnd() {Logger_Mutex.UnLock(); return '\n';}
70 
71 // xlogFD() returns the FD to be used by external programs as their STDERR.
72 // A negative one indicates that no special FD is assigned.
73 //
74 int xlogFD();
75 
76 private:
77 
79 static int extLFD[4];
80 long long eKeep;
81 char TBuff[24]; // Trace header buffer
82 int eFD;
83 int baseFD;
84 char *ePath;
85 char Filesfx[8];
86 time_t eNTC;
87 int eInt;
88 time_t eNow;
89 int doLFR;
90 
91 void putEmsg(char *msg, int msz);
92 int ReBind(int dorename=1);
93 void Trim();
94 };
95 #endif