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 
51 {
52 public:
53 
54 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
62 
63  XrdSysLogger(int ErrFD=STDERR_FILENO, int xrotate=1);
64 
65 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
68 
70  {
72  if (ePath)
73  free(ePath);
74  }
75 
76 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
81 
82 void AddMsg(const char *msg);
83 
84 //-----------------------------------------------------------------------------
88 //-----------------------------------------------------------------------------
89 
90 class Task
91 {
92 public:
93 friend class XrdSysLogger;
94 
95 virtual void Ring() = 0;
96 
97 inline Task *Next() {return next;}
98 
99  Task() : next(0) {}
100 virtual ~Task() {}
101 
102 private:
104 };
105 
106 void AtMidnight(Task *mnTask);
107 
108 //-----------------------------------------------------------------------------
130 //-----------------------------------------------------------------------------
131 
132 static const int onFifo = (int)0x80000000;
133 
134 int Bind(const char *path, int lfh=0);
135 
136 //-----------------------------------------------------------------------------
138 //-----------------------------------------------------------------------------
139 
140 void Flush() {fsync(eFD);}
141 
142 //-----------------------------------------------------------------------------
146 //-----------------------------------------------------------------------------
147 
148 int originalFD() {return baseFD;}
149 
150 //-----------------------------------------------------------------------------
159 //-----------------------------------------------------------------------------
160 
161 int ParseKeep(const char *arg);
162 
163 //-----------------------------------------------------------------------------
169 //-----------------------------------------------------------------------------
170 
171 void Put(int iovcnt, struct iovec *iov);
172 
173 //-----------------------------------------------------------------------------
175 //-----------------------------------------------------------------------------
176 
177 static
178 void setForwarding(bool onoff) {doForward = onoff;}
179 
180 //-----------------------------------------------------------------------------
182 //-----------------------------------------------------------------------------
183 
184 void setHiRes() {hiRes = true;}
185 
186 //-----------------------------------------------------------------------------
191 //-----------------------------------------------------------------------------
192 
193 void setKeep(long long knum) {eKeep = knum;}
194 
195 //-----------------------------------------------------------------------------
200 //-----------------------------------------------------------------------------
201 
202 void setRotate(int onoff) {doLFR = onoff;}
203 
204 //-----------------------------------------------------------------------------
209 //-----------------------------------------------------------------------------
210 
211 char *traceBeg() {Logger_Mutex.Lock(); Time(TBuff); return TBuff;}
212 
213 //-----------------------------------------------------------------------------
218 //-----------------------------------------------------------------------------
219 
220 char traceEnd() {Logger_Mutex.UnLock(); return '\n';}
221 
222 //-----------------------------------------------------------------------------
226 //-----------------------------------------------------------------------------
227 
228 const char *xlogFN() {return (ePath ? ePath : "stderr");}
229 
230 //-----------------------------------------------------------------------------
233 //-----------------------------------------------------------------------------
234 
235 void zHandler();
236 
237 private:
238 int FifoMake();
239 void FifoWait();
240 int Time(char *tbuff);
241 static int TimeStamp(struct timeval &tVal, unsigned long tID,
242  char *tbuff, int tbsz, bool hires);
243 int HandleLogRotateLock( bool dorotate );
244 void RmLogRotateLock();
245 
246 struct mmMsg
248  int mlen;
249  char *msg;
250  };
254 long long eKeep;
255 char TBuff[32]; // Trace header buffer
256 int eFD;
257 int baseFD;
258 char *ePath;
259 char Filesfx[8];
260 int eInt;
262 char *fifoFN;
263 bool hiRes;
264 bool doLFR;
265 pthread_t lfhTID;
266 
267 static bool doForward;
268 
269 void putEmsg(char *msg, int msz);
270 int ReBind(int dorename=1);
271 void Trim();
272 };
273 #endif
int originalFD()
Definition: XrdSysLogger.hh:148
char Filesfx[8]
Definition: XrdSysLogger.hh:259
Task * next
Definition: XrdSysLogger.hh:103
~XrdSysLogger()
Destructor.
Definition: XrdSysLogger.hh:69
int mlen
Definition: XrdSysLogger.hh:248
char * traceBeg()
Definition: XrdSysLogger.hh:211
static int TimeStamp(struct timeval &tVal, unsigned long tID, char *tbuff, int tbsz, bool hires)
Task * taskQ
Definition: XrdSysLogger.hh:252
int baseFD
Definition: XrdSysLogger.hh:257
void RmLogRotateLock()
void setRotate(int onoff)
Definition: XrdSysLogger.hh:202
int ReBind(int dorename=1)
int Time(char *tbuff)
void FifoWait()
Task()
Definition: XrdSysLogger.hh:99
void Put(int iovcnt, struct iovec *iov)
void zHandler()
char * msg
Definition: XrdSysLogger.hh:249
char * fifoFN
Definition: XrdSysLogger.hh:262
Task * Next()
Definition: XrdSysLogger.hh:97
Definition: XrdSysLogger.hh:90
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:193
void setHiRes()
Set log file timstamp to high resolution (hh:mm:ss.uuuu).
Definition: XrdSysLogger.hh:184
int eFD
Definition: XrdSysLogger.hh:256
XrdSysMutex Logger_Mutex
Definition: XrdSysLogger.hh:253
bool hiRes
Definition: XrdSysLogger.hh:263
static void setForwarding(bool onoff)
Set call-out to logging plug-in on or off.
Definition: XrdSysLogger.hh:178
virtual ~Task()
Definition: XrdSysLogger.hh:100
void AddMsg(const char *msg)
void putEmsg(char *msg, int msz)
int eInt
Definition: XrdSysLogger.hh:260
static bool doForward
Definition: XrdSysLogger.hh:267
int ParseKeep(const char *arg)
pthread_t lfhTID
Definition: XrdSysLogger.hh:265
const char * xlogFN()
Definition: XrdSysLogger.hh:228
Definition: XrdSysLogger.hh:50
mmMsg * msgList
Definition: XrdSysLogger.hh:251
Definition: XrdSysLogger.hh:246
void Flush()
Flush any pending output.
Definition: XrdSysLogger.hh:140
void Lock()
Definition: XrdSysPthread.hh:149
mmMsg * next
Definition: XrdSysLogger.hh:247
void AtMidnight(Task *mnTask)
virtual void Ring()=0
This method gets called at midnight.
char * ePath
Definition: XrdSysLogger.hh:258
int reserved1
Definition: XrdSysLogger.hh:261
char TBuff[32]
Definition: XrdSysLogger.hh:255
void UnLock()
Definition: XrdSysPthread.hh:151
bool doLFR
Definition: XrdSysLogger.hh:264
char traceEnd()
Definition: XrdSysLogger.hh:220
static const int onFifo
Definition: XrdSysLogger.hh:132
long long eKeep
Definition: XrdSysLogger.hh:254