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 /*Produced by Andrew Hanushevsky for Stanford University under contract */
9 /* DE-AC02-76-SFO0515 with the Deprtment of Energy */
10 /* */
11 /* This file is part of the XRootD software suite. */
12 /* */
13 /* XRootD is free software: you can redistribute it and/or modify it under */
14 /* the terms of the GNU Lesser General Public License as published by the */
15 /* Free Software Foundation, either version 3 of the License, or (at your */
16 /* option) any later version. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /******************************************************************************/
31 
32 #include <stdlib.h>
33 #ifndef WIN32
34 #include <unistd.h>
35 #include <string.h>
36 #include <strings.h>
37 #else
38 #include <string.h>
39 #include <io.h>
40 #include "XrdSys/XrdWin32.hh"
41 #endif
42 
43 #include "XrdSys/XrdSysPthread.hh"
44 
45 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
49 
50 class XrdOucTListFIFO;
51 
53 {
54 public:
55 
56 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
64 
65  XrdSysLogger(int ErrFD=STDERR_FILENO, int xrotate=1);
66 
67 //-----------------------------------------------------------------------------
69 //-----------------------------------------------------------------------------
70 
72  {
74  if (ePath)
75  free(ePath);
76  }
77 
78 //-----------------------------------------------------------------------------
82 //-----------------------------------------------------------------------------
83 
84 void AddMsg(const char *msg);
85 
86 //-----------------------------------------------------------------------------
90 //-----------------------------------------------------------------------------
91 
92 class Task
93 {
94 public:
95 friend class XrdSysLogger;
96 
97 virtual void Ring() = 0;
98 
99 inline Task *Next() {return next;}
100 
101  Task() : next(0) {}
102 virtual ~Task() {}
103 
104 private:
106 };
107 
108 void AtMidnight(Task *mnTask);
109 
110 //-----------------------------------------------------------------------------
132 //-----------------------------------------------------------------------------
133 
134 static const int onFifo = (int)0x80000000;
135 
136 int Bind(const char *path, int lfh=0);
137 
138 //-----------------------------------------------------------------------------
144 //-----------------------------------------------------------------------------
145 
146 void Capture(XrdOucTListFIFO *tFIFO);
147 
148 //-----------------------------------------------------------------------------
150 //-----------------------------------------------------------------------------
151 
152 void Flush() {fsync(eFD);}
153 
154 //-----------------------------------------------------------------------------
158 //-----------------------------------------------------------------------------
159 
160 int originalFD() {return baseFD;}
161 
162 //-----------------------------------------------------------------------------
171 //-----------------------------------------------------------------------------
172 
173 int ParseKeep(const char *arg);
174 
175 //-----------------------------------------------------------------------------
181 //-----------------------------------------------------------------------------
182 
183 void Put(int iovcnt, struct iovec *iov);
184 
185 //-----------------------------------------------------------------------------
187 //-----------------------------------------------------------------------------
188 
189 static
190 void setForwarding(bool onoff) {doForward = onoff;}
191 
192 //-----------------------------------------------------------------------------
194 //-----------------------------------------------------------------------------
195 
196 void setHiRes() {hiRes = true;}
197 
198 //-----------------------------------------------------------------------------
203 //-----------------------------------------------------------------------------
204 
205 void setKeep(long long knum) {eKeep = knum;}
206 
207 //-----------------------------------------------------------------------------
212 //-----------------------------------------------------------------------------
213 
214 void setRotate(int onoff) {doLFR = onoff;}
215 
216 //-----------------------------------------------------------------------------
221 //-----------------------------------------------------------------------------
222 
223 char *traceBeg() {Logger_Mutex.Lock(); Time(TBuff); return TBuff;}
224 
225 //-----------------------------------------------------------------------------
230 //-----------------------------------------------------------------------------
231 
232 char traceEnd() {Logger_Mutex.UnLock(); return '\n';}
233 
234 //-----------------------------------------------------------------------------
238 //-----------------------------------------------------------------------------
239 
240 const char *xlogFN() {return (ePath ? ePath : "stderr");}
241 
242 //-----------------------------------------------------------------------------
245 //-----------------------------------------------------------------------------
246 
247 void zHandler();
248 
249 private:
250 int FifoMake();
251 void FifoWait();
252 int Time(char *tbuff);
253 static int TimeStamp(struct timeval &tVal, unsigned long tID,
254  char *tbuff, int tbsz, bool hires);
255 int HandleLogRotateLock( bool dorotate );
256 void RmLogRotateLock();
257 
258 struct mmMsg
260  int mlen;
261  char *msg;
262  };
266 long long eKeep;
267 char TBuff[32]; // Trace header buffer
268 int eFD;
269 int baseFD;
270 char *ePath;
271 char Filesfx[8];
272 int eInt;
274 char *fifoFN;
275 bool hiRes;
276 bool doLFR;
277 pthread_t lfhTID;
278 
279 static bool doForward;
280 
281 void putEmsg(char *msg, int msz);
282 int ReBind(int dorename=1);
283 void Trim();
284 };
285 #endif
int originalFD()
Definition: XrdSysLogger.hh:160
char Filesfx[8]
Definition: XrdSysLogger.hh:271
Task * next
Definition: XrdSysLogger.hh:105
~XrdSysLogger()
Destructor.
Definition: XrdSysLogger.hh:71
int mlen
Definition: XrdSysLogger.hh:260
char * traceBeg()
Definition: XrdSysLogger.hh:223
static int TimeStamp(struct timeval &tVal, unsigned long tID, char *tbuff, int tbsz, bool hires)
Task * taskQ
Definition: XrdSysLogger.hh:264
int baseFD
Definition: XrdSysLogger.hh:269
Definition: XrdOucTList.hh:98
void RmLogRotateLock()
void setRotate(int onoff)
Definition: XrdSysLogger.hh:214
int ReBind(int dorename=1)
int Time(char *tbuff)
void FifoWait()
Task()
Definition: XrdSysLogger.hh:101
void Put(int iovcnt, struct iovec *iov)
void zHandler()
char * msg
Definition: XrdSysLogger.hh:261
char * fifoFN
Definition: XrdSysLogger.hh:274
void Capture(XrdOucTListFIFO *tFIFO)
Task * Next()
Definition: XrdSysLogger.hh:99
Definition: XrdSysLogger.hh:92
int HandleLogRotateLock(bool dorotate)
XrdSysLogger(int ErrFD=STDERR_FILENO, int xrotate=1)
Definition: XrdSysPthread.hh:140
int Bind(const char *path, int lfh=0)
void setKeep(long long knum)
Definition: XrdSysLogger.hh:205
void setHiRes()
Set log file timstamp to high resolution (hh:mm:ss.uuuu).
Definition: XrdSysLogger.hh:196
int eFD
Definition: XrdSysLogger.hh:268
XrdSysMutex Logger_Mutex
Definition: XrdSysLogger.hh:265
bool hiRes
Definition: XrdSysLogger.hh:275
static void setForwarding(bool onoff)
Set call-out to logging plug-in on or off.
Definition: XrdSysLogger.hh:190
virtual ~Task()
Definition: XrdSysLogger.hh:102
void AddMsg(const char *msg)
void putEmsg(char *msg, int msz)
int eInt
Definition: XrdSysLogger.hh:272
static bool doForward
Definition: XrdSysLogger.hh:279
int ParseKeep(const char *arg)
pthread_t lfhTID
Definition: XrdSysLogger.hh:277
const char * xlogFN()
Definition: XrdSysLogger.hh:240
Definition: XrdSysLogger.hh:52
mmMsg * msgList
Definition: XrdSysLogger.hh:263
Definition: XrdSysLogger.hh:258
void Flush()
Flush any pending output.
Definition: XrdSysLogger.hh:152
void Lock()
Definition: XrdSysPthread.hh:149
mmMsg * next
Definition: XrdSysLogger.hh:259
void AtMidnight(Task *mnTask)
virtual void Ring()=0
This method gets called at midnight.
char * ePath
Definition: XrdSysLogger.hh:270
int reserved1
Definition: XrdSysLogger.hh:273
char TBuff[32]
Definition: XrdSysLogger.hh:267
void UnLock()
Definition: XrdSysPthread.hh:151
bool doLFR
Definition: XrdSysLogger.hh:276
char traceEnd()
Definition: XrdSysLogger.hh:232
static const int onFifo
Definition: XrdSysLogger.hh:134
long long eKeep
Definition: XrdSysLogger.hh:266