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 
46 {
47 public:
48  XrdSysLogger(int ErrFD=STDERR_FILENO, int xrotate=1);
49 
50  ~XrdSysLogger() {if (ePath) free(ePath);}
51 
52 // Bind allows you to bind standard error to a file with an optional periodic
53 // closing and opening of the file.
54 //
55 int Bind(const char *path, int intsec=0);
56 
57 // Flush any pending output
58 //
59 void Flush() {fsync(eFD);}
60 
61 // originalFD() returns the base FD that we started with
62 //
63 int originalFD() {return baseFD;}
64 
65 // Output data and optionally prefix with date/time
66 //
67 void Put(int iovcnt, struct iovec *iov);
68 
69 // Set log file keep value. A negative number means keep abs() files.
70 // A positive number means keep no more than n bytes.
71 //
72 void setKeep(long long knum) {eKeep = knum;}
73 
74 // Set log file rotation on/off. Used by forked processes.
75 //
76 void setRotate(int onoff) {doLFR = onoff;}
77 
78 // Return formated date/time (tbuff must be atleast 24 characters)
79 //
80 int Time(char *tbuff);
81 
82 // traceBeg() obtains the logger lock and returns a message header.
83 // traceEnd() releases the logger lock and returns a newline
84 //
85 char *traceBeg() {Logger_Mutex.Lock(); Time(TBuff); return TBuff;}
86 char traceEnd() {Logger_Mutex.UnLock(); return '\n';}
87 
88 // xlogFD() returns the FD to be used by external programs as their STDERR.
89 // A negative one indicates that no special FD is assigned.
90 //
91 int xlogFD();
92 
93 private:
94 
96 static int extLFD[4];
97 long long eKeep;
98 char TBuff[24]; // Trace header buffer
99 int eFD;
100 int baseFD;
101 char *ePath;
102 char Filesfx[8];
103 time_t eNTC;
104 int eInt;
105 time_t eNow;
106 int doLFR;
107 
108 void putEmsg(char *msg, int msz);
109 int ReBind(int dorename=1);
110 void Trim();
111 };
112 #endif