xrootd
Loading...
Searching...
No Matches
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 <cstdlib>
33#ifndef WIN32
34#include <unistd.h>
35#include <cstring>
36#include <strings.h>
37#else
38#include <cstring>
39#include <io.h>
40#include "XrdSys/XrdWin32.hh"
41#endif
42
44
45//-----------------------------------------------------------------------------
48//-----------------------------------------------------------------------------
49
50class XrdOucTListFIFO;
51
53{
54public:
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
84void AddMsg(const char *msg);
85
86//-----------------------------------------------------------------------------
90//-----------------------------------------------------------------------------
91
92class Task
93{
94public:
95friend class XrdSysLogger;
96
97virtual void Ring() = 0;
98
99inline Task *Next() {return next;}
100
101 Task() : next(0) {}
102virtual ~Task() {}
103
104private:
106};
107
108void AtMidnight(Task *mnTask);
109
110//-----------------------------------------------------------------------------
132//-----------------------------------------------------------------------------
133
134static const int onFifo = (int)0x80000000;
135
136int Bind(const char *path, int lfh=0);
137
138//-----------------------------------------------------------------------------
144//-----------------------------------------------------------------------------
145
147
148//-----------------------------------------------------------------------------
150//-----------------------------------------------------------------------------
151
152void Flush() {fsync(eFD);}
153
154//-----------------------------------------------------------------------------
158//-----------------------------------------------------------------------------
159
160int originalFD() {return baseFD;}
161
162//-----------------------------------------------------------------------------
171//-----------------------------------------------------------------------------
172
173int ParseKeep(const char *arg);
174
175//-----------------------------------------------------------------------------
181//-----------------------------------------------------------------------------
182
183void Put(int iovcnt, struct iovec *iov);
184
185//-----------------------------------------------------------------------------
187//-----------------------------------------------------------------------------
188
189static
190void setForwarding(bool onoff) {doForward = onoff;}
191
192//-----------------------------------------------------------------------------
194//-----------------------------------------------------------------------------
195
196void setHiRes() {hiRes = true;}
197
198//-----------------------------------------------------------------------------
203//-----------------------------------------------------------------------------
204
205void setKeep(long long knum) {eKeep = knum;}
206
207//-----------------------------------------------------------------------------
212//-----------------------------------------------------------------------------
213
214void setRotate(int onoff) {doLFR = onoff;}
215
216//-----------------------------------------------------------------------------
221//-----------------------------------------------------------------------------
222
223char *traceBeg() {Logger_Mutex.Lock(); Time(TBuff); return TBuff;}
224
225//-----------------------------------------------------------------------------
230//-----------------------------------------------------------------------------
231
232char traceEnd() {Logger_Mutex.UnLock(); return '\n';}
233
234//-----------------------------------------------------------------------------
238//-----------------------------------------------------------------------------
239
240const char *xlogFN() {return (ePath ? ePath : "stderr");}
241
242//-----------------------------------------------------------------------------
245//-----------------------------------------------------------------------------
246
247void zHandler();
248
249private:
251void FifoWait();
252int Time(char *tbuff);
253static int TimeStamp(struct timeval &tVal, unsigned long tID,
254 char *tbuff, int tbsz, bool hires);
255int HandleLogRotateLock( bool dorotate );
257
258struct mmMsg
260 int mlen;
261 char *msg;
262 };
266long long eKeep;
267char TBuff[32]; // Trace header buffer
268int eFD;
270char *ePath;
271char Filesfx[8];
274char *fifoFN;
275bool hiRes;
276bool doLFR;
277pthread_t lfhTID;
278
279static bool doForward;
280
281void putEmsg(char *msg, int msz);
282int ReBind(int dorename=1);
283void Trim();
284};
285#endif
#define fsync(a)
Definition XrdPosix.hh:59
Definition XrdOucTList.hh:99
Definition XrdSysLogger.hh:93
Task()
Definition XrdSysLogger.hh:101
virtual void Ring()=0
This method gets called at midnight.
virtual ~Task()
Definition XrdSysLogger.hh:102
Task * Next()
Definition XrdSysLogger.hh:99
Task * next
Definition XrdSysLogger.hh:105
Definition XrdSysLogger.hh:53
int eFD
Definition XrdSysLogger.hh:268
int eInt
Definition XrdSysLogger.hh:272
char traceEnd()
Definition XrdSysLogger.hh:232
void RmLogRotateLock()
void putEmsg(char *msg, int msz)
bool doLFR
Definition XrdSysLogger.hh:276
void zHandler()
char * ePath
Definition XrdSysLogger.hh:270
void setKeep(long long knum)
Definition XrdSysLogger.hh:205
char TBuff[32]
Definition XrdSysLogger.hh:267
static const int onFifo
Definition XrdSysLogger.hh:134
bool hiRes
Definition XrdSysLogger.hh:275
void setHiRes()
Set log file timstamp to high resolution (hh:mm:ss.uuuu).
Definition XrdSysLogger.hh:196
void Flush()
Flush any pending output.
Definition XrdSysLogger.hh:152
char * traceBeg()
Definition XrdSysLogger.hh:223
int reserved1
Definition XrdSysLogger.hh:273
void Put(int iovcnt, struct iovec *iov)
Task * taskQ
Definition XrdSysLogger.hh:264
void AddMsg(const char *msg)
XrdSysMutex Logger_Mutex
Definition XrdSysLogger.hh:265
char * fifoFN
Definition XrdSysLogger.hh:274
XrdSysLogger(int ErrFD=STDERR_FILENO, int xrotate=1)
void FifoWait()
long long eKeep
Definition XrdSysLogger.hh:266
static int TimeStamp(struct timeval &tVal, unsigned long tID, char *tbuff, int tbsz, bool hires)
static void setForwarding(bool onoff)
Set call-out to logging plug-in on or off.
Definition XrdSysLogger.hh:190
void setRotate(int onoff)
Definition XrdSysLogger.hh:214
mmMsg * msgList
Definition XrdSysLogger.hh:263
void AtMidnight(Task *mnTask)
const char * xlogFN()
Definition XrdSysLogger.hh:240
pthread_t lfhTID
Definition XrdSysLogger.hh:277
int baseFD
Definition XrdSysLogger.hh:269
void Capture(XrdOucTListFIFO *tFIFO)
int Bind(const char *path, int lfh=0)
char Filesfx[8]
Definition XrdSysLogger.hh:271
int originalFD()
Definition XrdSysLogger.hh:160
int ReBind(int dorename=1)
int Time(char *tbuff)
~XrdSysLogger()
Destructor.
Definition XrdSysLogger.hh:71
static bool doForward
Definition XrdSysLogger.hh:279
int HandleLogRotateLock(bool dorotate)
int ParseKeep(const char *arg)
Definition XrdSysPthread.hh:165
void Lock()
Definition XrdSysPthread.hh:222
void UnLock()
Definition XrdSysPthread.hh:224
Definition XrdSysLogger.hh:259
char * msg
Definition XrdSysLogger.hh:261
mmMsg * next
Definition XrdSysLogger.hh:259
int mlen
Definition XrdSysLogger.hh:260
Definition XrdOucIOVec.hh:65