XRootD
XrdOucLogging Class Reference

#include <XrdOucLogging.hh>

+ Collaboration diagram for XrdOucLogging:

Classes

struct  configLogInfo
 

Public Member Functions

 XrdOucLogging ()
 
 ~XrdOucLogging ()
 

Static Public Member Functions

static bool configLog (XrdSysError &eDest, configLogInfo &logInfo)
 

Detailed Description

Definition at line 36 of file XrdOucLogging.hh.

Constructor & Destructor Documentation

◆ XrdOucLogging()

XrdOucLogging::XrdOucLogging ( )
inline

Definition at line 53 of file XrdOucLogging.hh.

53 {}

◆ ~XrdOucLogging()

XrdOucLogging::~XrdOucLogging ( )
inline

Definition at line 54 of file XrdOucLogging.hh.

54 {}

Member Function Documentation

◆ configLog()

bool XrdOucLogging::configLog ( XrdSysError eDest,
XrdOucLogging::configLogInfo logInfo 
)
static

Definition at line 111 of file XrdOucLogging.cc.

113 {
114  struct tmpstr {char *arg; char *arg2, *arg3;
115  tmpstr(const char *str) : arg(strdup(str)),
116  arg2(0), arg3(0) {}
117  ~tmpstr() {if (arg) free(arg);
118  if (arg2) free(arg2);
119  if (arg3) free(arg3);
120  }
121  };
122 
123  static XrdVERSIONINFODEF(myVersion, XrdLogConfig, XrdVNUMBER, XrdVERSION);
124  XrdSysLogging::Parms logParms;
125  char *logPI = 0, *logFN = 0;
126  int argc;
127 
128 // Check for stderr output
129 //
130  if (!strcmp(logInfo.logArg, "-")) return true;
131  tmpstr opt(logInfo.logArg);
132 
133 // Check if this specified a plugin
134 //
135  if (*opt.arg == '@')
136  {char *parms = index(opt.arg, ',');
137  logPI = opt.arg+1;
138  if (!(*logPI))
139  {eDest.Emsg("Config", "Log plugin library not specified.");
140  return false;
141  }
142  if (parms)
143  {char *eol, *pval;
144  int rc;
145  opt.arg3 = strdup(parms); *parms = 0; parms = opt.arg3;
146  if ((pval = varVal(",bsz=", parms, eol, ',')))
147  {long long bsz;
148  rc = XrdOuca2x::a2sz(eDest,"-l bsz",pval,&bsz,0,1048576);
149  if (eol) *eol = ',';
150  if (rc < 0) return false;
151  if (bsz && bsz < 8192) bsz = 8192;
152  logParms.bufsz = static_cast<int>(bsz);
153  }
154  if ((pval = varVal(",cse=", parms, eol, ',')))
155  {rc = XrdOuca2x::a2i(eDest,"-l cse",pval,&cseLvl,0,2);
156  if (eol) *eol = ',';
157  if (rc < 0) return false;
158  }
159  logFN = varVal(",logfn=", parms, eol, ',');
160  }
161  } else logFN = opt.arg;
162 
163 // Handle any logfile name
164 //
165  if (logFN)
166  { if (*logFN == '=')
167  {if (*(logFN+1) == '\0')
168  {eDest.Emsg("Config", "Logfile name not specified.");
169  return false;
170  }
171  logParms.logfn = ++logFN;
172  }
173  else if (strcmp(logFN, "-"))
174  {if (!(logFN = XrdOucUtils::subLogfn(eDest,logInfo.iName,strdup(logFN))))
175  return false;
176  logParms.logfn = opt.arg2 = logFN;
177  }
178  else logParms.logfn = logFN;
179  }
180 
181 // Handle plugin, if any
182 //
183  if (logPI)
184  {XrdSysLogPInit_t logPInit;
185  XrdOucPinLoader lpiLib(&eDest, &myVersion, "logging", logPI);
186  char **lpiArgs = configLPIArgs(logInfo.xrdEnv, argc);
187  if (!(logPInit = (XrdSysLogPInit_t)lpiLib.Resolve("XrdSysLogPInit")))
188  {eDest.Emsg("Config","Unable to find logging plugin object in",logPI);
189  lpiLib.Unload();
190  return false;
191  }
192  if (!(logParms.logpi = (*logPInit)(logInfo.cfgFn, lpiArgs, argc)))
193  {eDest.Emsg("Config", "Logging plugin initialization failed.");
194  lpiLib.Unload();
195  return false;
196  }
197  }
198 
199 // Now complete logging configuration
200 //
201  logParms.keepV = logInfo.keepV;
202  logParms.hiRes = logInfo.hiRes;
203  if (!XrdSysLogging::Configure(*(eDest.logger()), logParms))
204  {eDest.Emsg("Config", "Log configuration failed.");
205  return false;
206  }
207 
208 // Export the directory where the log file exists. We can modify the logfn
209 // as it should have been copied. Note logFN is the same as logParms.logfn.
210 //
211 
212  if (logFN && (logPI = rindex(logFN,'/'))) *(logPI+1) = '\0';
213  else logParms.logfn = "./";
214  XrdOucEnv::Export("XRDLOGDIR", logParms.logfn);
215 
216 // If there is a plugin but alternate output has not been specified, then we
217 // must capture stderr output and feed it to the logging plugin.
218 //
219  if (logPI && !logFN && cseLvl)
220  {pthread_t tid;
221  int pipeFD[2], dupStdErr = XrdSysFD_Dup(STDERR_FILENO);
222  if (dupStdErr < 0 || XrdSysFD_Pipe(pipeFD) < 0
223  || XrdSysFD_Dup2(pipeFD[1], STDERR_FILENO) < 0)
224  {eDest.Emsg("Config",errno, "creating a pipe to capture stderr.");
225  close(dupStdErr);
226  return false;
227  }
228  close(pipeFD[1]);
229  if (XrdSysThread::Run(&tid,LoggingStdErr,(void *)0,0,"stderr router"))
230  {XrdSysFD_Dup2(dupStdErr, STDERR_FILENO);
231  eDest.Emsg("Config", errno, "start stderr router");
232  close(pipeFD[0]); close(dupStdErr); return false;
233  }
234  stdErr = pipeFD[0];
235  close(dupStdErr);
236  }
237 
238 
239 // All done
240 //
241  return true;
242 }
static XrdSysError eDest(0,"crypto_")
#define close(a)
Definition: XrdPosix.hh:43
XrdSysLogPI_t(* XrdSysLogPInit_t)(const char *cfgn, char **argv, int argc)
Definition: XrdSysLogPI.hh:77
static int Export(const char *Var, const char *Val)
Definition: XrdOucEnv.cc:188
static char * subLogfn(XrdSysError &eDest, const char *inst, char *logfn)
static int a2i(XrdSysError &, const char *emsg, const char *item, int *val, int minv=-1, int maxv=-1)
Definition: XrdOuca2x.cc:45
static int a2sz(XrdSysError &, const char *emsg, const char *item, long long *val, long long minv=-1, long long maxv=-1)
Definition: XrdOuca2x.cc:257
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95
XrdSysLogger * logger(XrdSysLogger *lp=0)
Definition: XrdSysError.hh:141
static bool Configure(XrdSysLogger &logr, Parms &parms)
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)
XrdVersionInfo myVersion
XrdVERSIONINFODEF(myVersion, cmsclient, XrdVNUMBER, XrdVERSION)
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

References XrdOuca2x::a2i(), XrdOuca2x::a2sz(), XrdSysLogging::Parms::bufsz, XrdOucLogging::configLogInfo::cfgFn, close, XrdSysLogging::Configure(), eDest, XrdSysError::Emsg(), XrdOucEnv::Export(), XrdOucLogging::configLogInfo::hiRes, XrdSysLogging::Parms::hiRes, XrdOucLogging::configLogInfo::iName, XrdOucLogging::configLogInfo::keepV, XrdSysLogging::Parms::keepV, XrdOucLogging::configLogInfo::logArg, XrdSysLogging::Parms::logfn, XrdSysError::logger(), XrdSysLogging::Parms::logpi, XrdCms::myVersion, XrdOucPinLoader::Resolve(), XrdSysThread::Run(), XrdOucUtils::subLogfn(), XrdOucPinLoader::Unload(), XrdOucLogging::configLogInfo::xrdEnv, and XrdCms::XrdVERSIONINFODEF().

Referenced by XrdConfig::Configure().

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

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