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 
69  ~XrdSysLogger() {if (ePath) free(ePath);}
70 
71 //-----------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------
76 
77 void AddMsg(const char *msg);
78 
79 //-----------------------------------------------------------------------------
83 //-----------------------------------------------------------------------------
84 
85 class Task
86 {
87 public:
88 friend class XrdSysLogger;
89 
90 virtual void Ring() = 0;
91 
92 inline Task *Next() {return next;}
93 
94  Task() : next(0) {}
95 virtual ~Task() {}
96 
97 private:
99 };
100 
101 void AtMidnight(Task *mnTask);
102 
103 //-----------------------------------------------------------------------------
125 //-----------------------------------------------------------------------------
126 
127 static const int onFifo = (int)0x80000000;
128 
129 int Bind(const char *path, int lfh=0);
130 
131 //-----------------------------------------------------------------------------
133 //-----------------------------------------------------------------------------
134 
135 void Flush() {fsync(eFD);}
136 
137 //-----------------------------------------------------------------------------
141 //-----------------------------------------------------------------------------
142 
143 int originalFD() {return baseFD;}
144 
145 //-----------------------------------------------------------------------------
154 //-----------------------------------------------------------------------------
155 
156 int ParseKeep(const char *arg);
157 
158 //-----------------------------------------------------------------------------
164 //-----------------------------------------------------------------------------
165 
166 void Put(int iovcnt, struct iovec *iov);
167 
168 //-----------------------------------------------------------------------------
170 //-----------------------------------------------------------------------------
171 
172 static
173 void setForwarding(bool onoff) {doForward = onoff;}
174 
175 //-----------------------------------------------------------------------------
177 //-----------------------------------------------------------------------------
178 
179 void setHiRes() {hiRes = true;}
180 
181 //-----------------------------------------------------------------------------
186 //-----------------------------------------------------------------------------
187 
188 void setKeep(long long knum) {eKeep = knum;}
189 
190 //-----------------------------------------------------------------------------
195 //-----------------------------------------------------------------------------
196 
197 void setRotate(int onoff) {doLFR = onoff;}
198 
199 //-----------------------------------------------------------------------------
204 //-----------------------------------------------------------------------------
205 
206 char *traceBeg() {Logger_Mutex.Lock(); Time(TBuff); return TBuff;}
207 
208 //-----------------------------------------------------------------------------
213 //-----------------------------------------------------------------------------
214 
215 char traceEnd() {Logger_Mutex.UnLock(); return '\n';}
216 
217 //-----------------------------------------------------------------------------
221 //-----------------------------------------------------------------------------
222 
223 const char *xlogFN() {return (ePath ? ePath : "stderr");}
224 
225 //-----------------------------------------------------------------------------
228 //-----------------------------------------------------------------------------
229 
230 void zHandler();
231 
232 private:
233 int FifoMake();
234 void FifoWait();
235 int Time(char *tbuff);
236 static int TimeStamp(struct timeval &tVal, unsigned long tID,
237  char *tbuff, int tbsz, bool hires);
238 
239 struct mmMsg
241  int mlen;
242  char *msg;
243  };
247 long long eKeep;
248 char TBuff[32]; // Trace header buffer
249 int eFD;
250 int baseFD;
251 char *ePath;
252 char Filesfx[8];
253 int eInt;
255 char *fifoFN;
256 bool hiRes;
257 bool doLFR;
258 pthread_t lfhTID;
259 
260 static bool doForward;
261 
262 void putEmsg(char *msg, int msz);
263 int ReBind(int dorename=1);
264 void Trim();
265 };
266 #endif
int originalFD()
Definition: XrdSysLogger.hh:143
char Filesfx[8]
Definition: XrdSysLogger.hh:252
Task * next
Definition: XrdSysLogger.hh:98
~XrdSysLogger()
Destructor.
Definition: XrdSysLogger.hh:69
int mlen
Definition: XrdSysLogger.hh:241
char * traceBeg()
Definition: XrdSysLogger.hh:206
static int TimeStamp(struct timeval &tVal, unsigned long tID, char *tbuff, int tbsz, bool hires)
Task * taskQ
Definition: XrdSysLogger.hh:245
int baseFD
Definition: XrdSysLogger.hh:250
void setRotate(int onoff)
Definition: XrdSysLogger.hh:197
int ReBind(int dorename=1)
int Time(char *tbuff)
void FifoWait()
Task()
Definition: XrdSysLogger.hh:94
void Put(int iovcnt, struct iovec *iov)
void zHandler()
char * msg
Definition: XrdSysLogger.hh:242
char * fifoFN
Definition: XrdSysLogger.hh:255
Task * Next()
Definition: XrdSysLogger.hh:92
Definition: XrdSysLogger.hh:85
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:188
void setHiRes()
Set log file timstamp to high resolution (hh:mm:ss.uuuu).
Definition: XrdSysLogger.hh:179
int eFD
Definition: XrdSysLogger.hh:249
XrdSysMutex Logger_Mutex
Definition: XrdSysLogger.hh:246
bool hiRes
Definition: XrdSysLogger.hh:256
static void setForwarding(bool onoff)
Set call-out to logging plug-in on or off.
Definition: XrdSysLogger.hh:173
virtual ~Task()
Definition: XrdSysLogger.hh:95
void AddMsg(const char *msg)
void putEmsg(char *msg, int msz)
int eInt
Definition: XrdSysLogger.hh:253
static bool doForward
Definition: XrdSysLogger.hh:260
int ParseKeep(const char *arg)
pthread_t lfhTID
Definition: XrdSysLogger.hh:258
const char * xlogFN()
Definition: XrdSysLogger.hh:223
Definition: XrdSysLogger.hh:50
mmMsg * msgList
Definition: XrdSysLogger.hh:244
Definition: XrdSysLogger.hh:239
void Flush()
Flush any pending output.
Definition: XrdSysLogger.hh:135
void Lock()
Definition: XrdSysPthread.hh:149
mmMsg * next
Definition: XrdSysLogger.hh:240
void AtMidnight(Task *mnTask)
virtual void Ring()=0
This method gets called at midnight.
char * ePath
Definition: XrdSysLogger.hh:251
int reserved1
Definition: XrdSysLogger.hh:254
char TBuff[32]
Definition: XrdSysLogger.hh:248
void UnLock()
Definition: XrdSysPthread.hh:151
bool doLFR
Definition: XrdSysLogger.hh:257
char traceEnd()
Definition: XrdSysLogger.hh:215
static const int onFifo
Definition: XrdSysLogger.hh:127
long long eKeep
Definition: XrdSysLogger.hh:247