XRootD
XrdSysLogging Class Reference

#include <XrdSysLogging.hh>

+ Collaboration diagram for XrdSysLogging:

Classes

struct  Parms
 Parameters to be passed to configure. More...
 

Public Member Functions

 XrdSysLogging ()
 
 ~XrdSysLogging ()
 

Static Public Member Functions

static bool Configure (XrdSysLogger &logr, Parms &parms)
 
static bool Forward (struct timeval mtime, unsigned long tID, struct iovec *iov, int iovcnt)
 

Detailed Description

Definition at line 47 of file XrdSysLogging.hh.

Constructor & Destructor Documentation

◆ XrdSysLogging()

XrdSysLogging::XrdSysLogging ( )
inline

Constructor and destructor

Definition at line 56 of file XrdSysLogging.hh.

56 {}

◆ ~XrdSysLogging()

XrdSysLogging::~XrdSysLogging ( )
inline

Definition at line 58 of file XrdSysLogging.hh.

58 {}

Member Function Documentation

◆ Configure()

bool XrdSysLogging::Configure ( XrdSysLogger logr,
Parms parms 
)
static

Configure the logger object using the parameters above.

Parameters
logrReference to the logger object.
parmsReference to the parameters.
Returns
true if successful and false if log could not be configured.

Definition at line 72 of file XrdSysLogging.cc.

73 {
74  char eBuff[256];
75  int rc;
76 
77 // Set logger parameters
78 //
79  if (parms.hiRes) logr.setHiRes();
80 
81 // If we are going to send output to a local destination, configure it.
82 //
83  if (parms.logfn)
84  {if (strcmp(parms.logfn, "-") && (rc=logr.Bind(parms.logfn,parms.keepV)))
85  {sprintf(eBuff, "Error %d (%s) binding to log file %s.\n",
86  -rc, XrdSysE2T(-rc), parms.logfn);
87  return EMsg(logr, eBuff);
88  }
89  lclOut = true;
90  }
91 
92 // If we are not sending output to a remote destination, we are done
93 //
94  if (!parms.logpi) {lclOut = true; return true;}
95  piLogger= parms.logpi;
96  logDone = !lclOut;
97  rmtOut = true;
98 
99 // We have a plugin, setup the synchronous case if so desired
100 //
101  if (!parms.bufsz)
102  {logr.setForwarding(true);
103  doSync = true;
104  return true;
105  }
106 
107 // Allocate a log buffer
108 //
109  int bsz = (parms.bufsz < 0 ? 65536 : parms.bufsz);
110  rc = posix_memalign((void **)&buffOrg, getpagesize(), bsz);
111  if (rc != 0 || !buffOrg) return EMsg(logr, "Unable to allocate log buffer!\n");
112 
113  buffBeg = buffOrg + buffOvhd;
114  buffEnd = buffOrg + bsz;
115 
116 // Start the forwarding thread
117 //
118  if (XrdSysThread::Run(&lpiTID, Send2PI, (void *)0, 0, "LogPI handler"))
119  {sprintf(eBuff, "Error %d (%s) starting LogPI handler.\n",
120  errno, XrdSysE2T(errno));
121  return EMsg(logr, eBuff);
122  }
123 
124 // We are all done
125 //
126  logr.setForwarding(true);
127  return true;
128 }
const char * XrdSysE2T(int errcode)
Definition: XrdSysE2T.cc:104
void setHiRes()
Set log file timstamp to high resolution (hh:mm:ss.uuuu).
static void setForwarding(bool onoff)
Set call-out to logging plug-in on or off.
int Bind(const char *path, int lfh=0)
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)

References XrdSysLogger::Bind(), XrdSysLogging::Parms::bufsz, XrdSysLogging::Parms::hiRes, XrdSysLogging::Parms::keepV, XrdSysLogging::Parms::logfn, XrdSysLogging::Parms::logpi, XrdSysThread::Run(), XrdSysLogger::setForwarding(), XrdSysLogger::setHiRes(), and XrdSysE2T().

Referenced by XrdOucLogging::configLog().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Forward()

bool XrdSysLogging::Forward ( struct timeval  mtime,
unsigned long  tID,
struct iovec *  iov,
int  iovcnt 
)
static

Forward a log message to a plugin.

Parameters
mtimeThe time the message was generated.
tIDThe thread ID that issued the message.
iovThe vector describing what to forward.
iovcntThe number of elements in iov vector.
Returns
false if the message needs to also be placed in a local log file. true if all processing has completed.

Definition at line 172 of file XrdSysLogging.cc.

174 {
175  MsgBuff *theMsg;
176  char *fence, *freeMsg, *msgText;
177  int dwords, msgLen = 0;
178  bool doPost = false;
179 
180 // Calculate the message length
181 //
182  for (int i = 0; i < iovcnt; i++) msgLen += iov[i].iov_len;
183 
184 // If we are doing synchronous forwarding, do so now (we do not get a lock)
185 //
186  if (doSync)
187  {char *mbP, mbuff[syncBSZ];
188  if (msgLen >= syncBSZ) msgLen = CopyTrunc(mbuff, iov, iovcnt);
189  else {mbP = mbuff;
190  for (int i = 0; i < iovcnt; i++)
191  {memcpy(mbP, iov[i].iov_base, iov[i].iov_len);
192  mbP += iov[i].iov_len;
193  }
194  *mbP = 0;
195  }
196  (*piLogger)(mtime, tID, mbuff, msgLen);
197  return logDone;
198  }
199 
200 // Serialize remainder of code
201 //
202  msgMutex.Lock();
203 
204 // If the message is excessively long, treat it as a lost message
205 //
206  if (msgLen > maxMsgLen)
207  {todLost = mtime;
208  numLost++;
209  msgMutex.UnLock();
210  return logDone;
211  }
212 
213 // Get the actual doublewords bytes we need (account for null byte in the msg).
214 // We need to increase the size by the header size if there are outsanding
215 // lost messages.
216 //
217  dwords = msgLen+8 + sizeof(MsgBuff);
218  if (numLost) dwords += sizeof(MsgBuff);
219  dwords = dwords/8;
220 
221 // Compute the allocation fence. The choices are as follows:
222 // a) When pendMsg is present then the fence is the end of the buffer if
223 // lastMsg >= pendMsg and pendMsg otherwise.
224 // b) When pendMsg is nil then we can reset the buffer pointers so that the
225 // fence is the end of the buffer.
226 //
227  if (pendMsg)
228  {freeMsg = lastMsg + ((MsgBuff *)lastMsg)->buffsz*8;
229  fence = (lastMsg >= pendMsg ? buffEnd : pendMsg);
230  } else {
231  freeMsg = buffBeg;
232  fence = buffEnd;
233  lastMsg = 0;
234  doPost = true;
235  }
236 
237 // Check if there is room for this message. If not, count this as a lost
238 // message and tell the caller full forwarding did not happen.
239 //
240  if ((freeMsg + (dwords*8)) > fence)
241  {todLost = mtime;
242  numLost++;
243  msgMutex.UnLock();
244  return logDone;
245  }
246 
247 // We can allocate everything. So, check if we will be inserting a lost
248 // message entry here. We preallocated this above when numLost != 0;
249 //
250  if (numLost)
251  {theMsg = (MsgBuff *)freeMsg;
252  theMsg->msgtod = mtime;
253  theMsg->tID = tID;
254  theMsg->buffsz = mbDwords;
255  theMsg->msglen = -numLost;
256  if (lastMsg) ((MsgBuff *)lastMsg)->next = freeMsg - buffOrg;
257  lastMsg = freeMsg;
258  freeMsg += msgOff;
259  }
260 
261 // Insert the message
262 //
263  theMsg = (MsgBuff *)freeMsg;
264  theMsg->msgtod = mtime;
265  theMsg->tID = tID;
266  theMsg->next = 0;
267  theMsg->buffsz = dwords;
268  theMsg->msglen = msgLen;
269  if (lastMsg) ((MsgBuff *)lastMsg)->next = freeMsg - buffOrg;
270  lastMsg = freeMsg;
271 
272 // Copy the message text into the buffer
273 //
274  msgText = freeMsg + msgOff;
275  for (int i = 0; i < iovcnt; i++)
276  {memcpy(msgText, iov[i].iov_base, iov[i].iov_len);
277  msgText += iov[i].iov_len;
278  }
279  *msgText = 0;
280 
281 // If we need to write this to another log file do so here.
282 //
283 
284 // Do final post processing (release the lock prior to posting)
285 //
286  if (doPost) pendMsg = freeMsg;
287  msgMutex.UnLock();
288  if (doPost) msgAlert.Post();
289  return logDone;
290 }

Referenced by XrdSysLogger::Put().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: