XRootD
XrdSysLogging.hh
Go to the documentation of this file.
1 #ifndef __SYS_LOGGING_H__
2 #define __SYS_LOGGING_H__
3 /******************************************************************************/
4 /* */
5 /* X r d S y s L o g g i n g . h h */
6 /* */
7 /*(c) 2016 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 <limits.h>
33 #include <cstdlib>
34 #include <sys/time.h>
35 #include <sys/uio.h>
36 
37 #include "XrdSys/XrdSysLogPI.hh"
38 #include "XrdSys/XrdSysPthread.hh"
39 
40 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
44 
45 class XrdSysLogger;
46 
48 {
49 public:
50 
51 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
55 
57 
59 
60 //-----------------------------------------------------------------------------
62 //-----------------------------------------------------------------------------
63 
64 struct Parms
65  {const char *logfn;
67  int bufsz;
68  int keepV;
69  bool hiRes;
70  Parms() : logfn(0), logpi(0), bufsz(-1), keepV(0), hiRes(false) {}
71  ~Parms() {}
72  };
73 
74 //-----------------------------------------------------------------------------
81 //-----------------------------------------------------------------------------
82 
83 static bool Configure(XrdSysLogger &logr, Parms &parms);
84 
85 //-----------------------------------------------------------------------------
95 //-----------------------------------------------------------------------------
96 
97 static bool Forward(struct timeval mtime, unsigned long tID,
98  struct iovec *iov, int iovcnt);
99 
100 private:
101 struct MsgBuff
102  {struct timeval msgtod; // time message was generated
103  unsigned long tID; // Thread ID issuing message
104  unsigned int next; // Offset to next message, 0 if none
105  unsigned short buffsz; // In doublewords (max is 512K-8)
106  short msglen; // Len of msg text (max 32K-1) if <0 ->lost msgs
107 // char msgtxt; // Text follows the message header
108  };
109 static const int msgOff = sizeof(MsgBuff);
110 static const int mbDwords = (sizeof(MsgBuff)+7)/8*8;
111 static const int maxMsgLen = SHRT_MAX;
112 
113 static int CopyTrunc(char *mbuff, struct iovec *iov, int iovcnt);
114 static bool EMsg(XrdSysLogger &logr, const char *msg);
115 static MsgBuff *getMsg(char **msgTxt, bool cont);
116 static void *Send2PI(void *arg);
117 
118 static pthread_t lpiTID;
119 static bool lclOut;
120 static bool rmtOut;
121 };
122 #endif
void(* XrdSysLogPI_t)(struct timeval const &mtime, unsigned long tID, const char *msg, int mlen)
Definition: XrdSysLogPI.hh:51
static bool Forward(struct timeval mtime, unsigned long tID, struct iovec *iov, int iovcnt)
static bool Configure(XrdSysLogger &logr, Parms &parms)
Parameters to be passed to configure.
XrdSysLogPI_t logpi
-> log plugin object or nil if none
int keepV
log keep argument
const char * logfn
-> log file name or nil if none.
bool hiRes
log using high resolution timestamp
int bufsz
size of message buffer, -1 default, or 0