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 void setHiRes() {hiRes = true;}
173 
174 //-----------------------------------------------------------------------------
179 //-----------------------------------------------------------------------------
180 
181 void setKeep(long long knum) {eKeep = knum;}
182 
183 //-----------------------------------------------------------------------------
188 //-----------------------------------------------------------------------------
189 
190 void setRotate(int onoff) {doLFR = onoff;}
191 
192 //-----------------------------------------------------------------------------
197 //-----------------------------------------------------------------------------
198 
199 char *traceBeg() {Logger_Mutex.Lock(); Time(TBuff); return TBuff;}
200 
201 //-----------------------------------------------------------------------------
206 //-----------------------------------------------------------------------------
207 
208 char traceEnd() {Logger_Mutex.UnLock(); return '\n';}
209 
210 //-----------------------------------------------------------------------------
214 //-----------------------------------------------------------------------------
215 
216 const char *xlogFN() {return (ePath ? ePath : "stderr");}
217 
218 //-----------------------------------------------------------------------------
221 //-----------------------------------------------------------------------------
222 
223 void zHandler();
224 
225 private:
226 int FifoMake();
227 void FifoWait();
228 int Time(char *tbuff);
229 
230 struct mmMsg
232  int mlen;
233  char *msg;
234  };
238 long long eKeep;
239 char TBuff[32]; // Trace header buffer
240 int eFD;
241 int baseFD;
242 char *ePath;
243 char Filesfx[8];
244 int eInt;
246 char *fifoFN;
247 bool hiRes;
248 bool doLFR;
249 pthread_t lfhTID;
250 
251 void putEmsg(char *msg, int msz);
252 int ReBind(int dorename=1);
253 void Trim();
254 };
255 #endif
int originalFD()
Definition: XrdSysLogger.hh:143
char Filesfx[8]
Definition: XrdSysLogger.hh:243
Task * next
Definition: XrdSysLogger.hh:98
~XrdSysLogger()
Destructor.
Definition: XrdSysLogger.hh:69
int mlen
Definition: XrdSysLogger.hh:232
char * traceBeg()
Definition: XrdSysLogger.hh:199
Task * taskQ
Definition: XrdSysLogger.hh:236
int baseFD
Definition: XrdSysLogger.hh:241
void setRotate(int onoff)
Definition: XrdSysLogger.hh:190
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:233
char * fifoFN
Definition: XrdSysLogger.hh:246
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:181
void setHiRes()
Set log file timstamp to high resolution (hh:mm:ss.uuuu).
Definition: XrdSysLogger.hh:172
int eFD
Definition: XrdSysLogger.hh:240
XrdSysMutex Logger_Mutex
Definition: XrdSysLogger.hh:237
bool hiRes
Definition: XrdSysLogger.hh:247
virtual ~Task()
Definition: XrdSysLogger.hh:95
void AddMsg(const char *msg)
void putEmsg(char *msg, int msz)
int eInt
Definition: XrdSysLogger.hh:244
int ParseKeep(const char *arg)
pthread_t lfhTID
Definition: XrdSysLogger.hh:249
const char * xlogFN()
Definition: XrdSysLogger.hh:216
Definition: XrdSysLogger.hh:50
mmMsg * msgList
Definition: XrdSysLogger.hh:235
Definition: XrdSysLogger.hh:230
void Flush()
Flush any pending output.
Definition: XrdSysLogger.hh:135
void Lock()
Definition: XrdSysPthread.hh:149
mmMsg * next
Definition: XrdSysLogger.hh:231
void AtMidnight(Task *mnTask)
virtual void Ring()=0
This method gets called at midnight.
char * ePath
Definition: XrdSysLogger.hh:242
int reserved1
Definition: XrdSysLogger.hh:245
char TBuff[32]
Definition: XrdSysLogger.hh:239
void UnLock()
Definition: XrdSysPthread.hh:151
bool doLFR
Definition: XrdSysLogger.hh:248
char traceEnd()
Definition: XrdSysLogger.hh:208
static const int onFifo
Definition: XrdSysLogger.hh:127
long long eKeep
Definition: XrdSysLogger.hh:238