StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StLoggerManager.cxx
1 // //
13 #include <assert.h>
14 #include <stdlib.h>
15 
16 #ifdef __ROOT__
17 #include "TROOT.h"
18 #include "TSystem.h"
19 #include "TString.h"
20 #include "TError.h"
21 #include "TEnv.h"
22 #include "TVirtualMutex.h"
23 #endif
24 
25 #ifndef _NO_IMPLEMENTATION_
26 #define _NO_IMPLEMENTATION_ { \
27  const char *text = __FUNCTION__; \
28  NDC::push(_T("NO IMPLEMENTATION")); \
29  PrintLogger(text,'D',""); \
30  NDC::pop(); \
31 }
32 #endif
33 // echo -e "\033[31m ME \033[0m COOL"
34 #define COLOR_NORMAL "\033[0m"
35 #define COLOR_RED "\033[31m"
36 #define COLOR_GREEN "\033[32m"
37 #define COLOR_YELLOW "\033[33m"
38 #define COLOR_BLUE "\033[34m"
39 #define COLOR_PINK "\033[35m"
40 
41 #include "StLoggerManager.h"
42 bool StLoggerManager::mColorEnabled = kFALSE;
43 
44 #include <log4cxx/basicconfigurator.h>
45 #include <log4cxx/propertyconfigurator.h>
46 #include <log4cxx/helpers/exception.h>
47 #include <log4cxx/ndc.h>
48 #include <log4cxx/consoleappender.h>
49 #include <log4cxx/patternlayout.h>
50 #include <log4cxx/layout.h>
51 #include <log4cxx/xml/domconfigurator.h>
52 //#include <log4cxx/varia/stringmatchfilter.h>
53 // #include <log4cxx/varia/denyallfilter.h>
54 
55 #include "StStarLogger/StUCMAppender.h"
56 
57 using namespace log4cxx;
58 using namespace log4cxx::helpers;
59 using namespace log4cxx::spi;
60 using namespace log4cxx::varia;
61 using namespace log4cxx::db;
62 #if (STAR_LOG4CXX_VERSION == 10)
63  using namespace log4cxx::filter;
64 #endif
65 using namespace std;
66 class StMessage {
67  public: StMessage(){}
68 };
69 
70 log4cxx::LoggerPtr StLoggerManager::fgQALogger;
71 log4cxx::LoggerPtr &StLoggerManager::fgUCMLogger = *(new log4cxx::LoggerPtr());
72 
73 const char *StLoggerManager::fgLevels = "FEWIDQU";
74 #ifdef __ROOT__
75 // ROOT Error handling subrotuine
76 //______________________________________________________________________________
77 static void Log4cxx4RootErrorHandler(Int_t level, Bool_t abort, const char *location, const char *msg)
78 {
79  // This is derived from the ROOT "default error handler function" TError.cxx
80  // The default error handler function. It prints the message on stderr and
81  // if abort is set it aborts the application.
82 
83 
84  // The level is defined by the current logger level
85  NDC::push("ROOT");
86 
87 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,00,0)
88 if (gErrorIgnoreLevel == kUnset) {
89 
90  R__LOCKGUARD2(gErrorMutex);
91 #else
92  {
93 #endif
94 
95  gErrorIgnoreLevel = 0;
96  if (gEnv) {
97  TString level = gEnv->GetValue("Root.ErrorIgnoreLevel", "Info");
98  if (!level.CompareTo("Info",TString::kIgnoreCase))
99  gErrorIgnoreLevel = kInfo;
100  else if (!level.CompareTo("Warning",TString::kIgnoreCase))
101  gErrorIgnoreLevel = kWarning;
102  else if (!level.CompareTo("Error",TString::kIgnoreCase))
103  gErrorIgnoreLevel = kError;
104  else if (!level.CompareTo("Break",TString::kIgnoreCase))
105  gErrorIgnoreLevel = kBreak;
106  else if (!level.CompareTo("SysError",TString::kIgnoreCase))
107  gErrorIgnoreLevel = kSysError;
108  else if (!level.CompareTo("Fatal",TString::kIgnoreCase))
109  gErrorIgnoreLevel = kFatal;
110  }
111  }
112 
113  if (level < gErrorIgnoreLevel)
114  return;
115 
116 
117  if (level >= kFatal) {
118  LOG_FATAL << location << msg << endm;
119  } else if (level >= kSysError) {
120  LOG_FATAL << location << " : " << msg << endm;
121  } else if (level >= kBreak) {
122  LOG_FATAL << location << " : " << msg << endm;
123  } else if (level >= kError) {
124  LOG_ERROR << location << " : " << msg << endm;
125 // else if (level >= kWarning)
126 // LOG_WARN << location << " : " << msg << endm;
127  } else if (level >= kInfo) {
128  LOG_INFO << location << " : " << msg << endm;
129  }
130 
131  if (abort) {
132  if (gSystem) {
133  gSystem->StackTrace();
134  gSystem->Abort();
135  } else
136  ::abort();
137  }
138  NDC::pop();
139 }
140 #endif
141 //________________________________________
142 std::ostream& StLoggerManager::OperatorShift(std::ostream& os, StMessage* stm) {
143 // std::ostream& operator<<(std::ostream& os, StMessage* stm) {
144  std::ostringstream &thisStream = Stream();
145  if ( (&thisStream == &os) && (stm == endm) ) {
146  // There was a StMessage terminator
147  os << ends;
148  StMessMgr::CurrentMessager()->Print();
149  os.seekp(0);os<< ends;os.seekp(0);
150  } else {
151  assert(0);
152  }
153  return os;
154 }
155 
156 //static const char defaultMessType = 'I';
157 //static char emptyString[] = "";
158 //static char oOpt[] = "O";
159 //static char otsOpt[] = "OTS";
160 //static char eOpt[] = "E";
161 //static char nullMess[] = "Null message!!!";
162 
163 StMessMgr* StLoggerManager::mInstance = 0;
164 //
165 // C++ routines:
166 //_____________________________________________________________________________
167 #ifdef __ROOT__
168 ClassImp(StLoggerManager)
169 #endif
170 //_____________________________________________________________________________
171 StLoggerManager::StLoggerManager(const char *loggerName)
172  : StMessMgr(), fCurType(0),fAllowRepeat(-1),fLastRepeatCounter(0),fStarOptionFilter(0)
173 {
174 //
175 // Constructor - only called once when the library is loaded to
176 // instantiate the global message manager.
177 //
178 // Format
179 // %c - logger name %c{2} = b.c ( a.b.c. )
180 // %d - date %d{%H:%M:%S} or %d{%d %b %Y %H:%M:%S}.
181 // a - short week date name, A - full week date name
182 // b - short month name, B - full month name m - month number (1-12)
183 // d - day of the month
184 // H - hours (0-23) I - hours ( 1 - 12)
185 // %F - the file name where the logging request was issued
186 // %l - location information of the caller which generated the logging event
187 // %L - the line number from where the logging request was issued
188 // %m - the application supplied message associated with the logging event
189 // %n - the platform dependent line separator character or characters
190 // %p - the level(priority) of the logging event
191 // %r - the number of milliseconds elapsed since the start
192 // %x - the NDC (nested diagnostic context)
193 //
194 // This is essentially the TTCC layout.
195 // %-6r [%15.15t] %-5p %30.30c %x - %m
196 
197 
198  unsigned int i;
199  for (i=0;i<strlen(fgLevels);i++){
200  fSourceFileNames.push_back("");
201  fLineNumbers[i] = -1;
202  }
203  fLogger = Logger::getLogger(_T(loggerName));
204  fDefaultLevel = fLogger->getLevel();
205 // fCurType = new char[ 2]; fCurType[0] = 0; fCurType[1] = 0;
206  fCurOpt = new char[32]; fCurOpt [0] = 0;
207  SwitchOff("D");
208  MemoryOn();
209 }
210 
211 //_____________________________________________________________________________
212 StLoggerManager::~StLoggerManager() {
213 //
214 // Destructor - must delete the message listsy
215 //
216 
217  fCurType = 0;
218  if (fCurOpt) delete [] fCurOpt; fCurOpt = 0;
219 
220  if (StLoggerManager::Instance() == this) {
221  // DestroyInstance();
222  gMessMgr = 0;
223  }
224 
225 }
226 //_____________________________________________________________________________
227 StMessMgr* StLoggerManager::Instantiate()
228 {return StLoggerManager::StarLoggerInit(); }
229 
230 //_____________________________________________________________________________
231 StMessMgr* StLoggerManager::Instantiate(const char *loggerName)
232 {return StLoggerManager::StarLoggerInit(loggerName); }
233 
234 //_____________________________________________________________________________
235 StMessMgr* StLoggerManager::StarLoggerInit(const char *loggerName)
236 {
237  return new StLoggerManager(loggerName);
238 }
239 //_____________________________________________________________________________
240 StMessMgr* StLoggerManager::StarLoggerInit() {
241 //
242 // Allows anyone to get a pointer to the single message manager:
243 // StLoggerManager::Instance()->(member function)
244 //
245  if (!mInstance) {
246  // BasicConfigurator::configure();
247  const char *proEnv = 0;
248 #ifndef __ROOT__
249  String propertyFile = "log4j.xml";
250 #else
251  TString Color = gEnv->GetValue("Logger.Color","no");
252  mColorEnabled = Color.CompareTo("no",TString::kIgnoreCase);
253  TString fullPropertyFileName = gEnv->GetValue("Logger.Configuration","log4j.xml");
254  gSystem->ExpandPathName(fullPropertyFileName);
255  String propertyFile = (const char*)fullPropertyFileName;
256  proEnv = gSystem->Getenv("STAR_LOGGER_PROPERTY");
257 #endif
258  StarOptionFilterPtr filter;
259  if (proEnv && proEnv[0] ) propertyFile=proEnv;
260  if (!gSystem->AccessPathName(propertyFile.c_str())) {
261  xml::DOMConfigurator::configure(propertyFile);
262 // PropertyConfigurator::configure(propertyFile);
263  } else {
264  // BasicConfigurator::configure();
265  LoggerPtr root = Logger::getRootLogger();
266  // Add the STAR default appender
267  ConsoleAppenderPtr appender = new ConsoleAppender(
268  new PatternLayout("%-3c{2}:%-5p - %m%n"));
269 // new PatternLayout(PatternLayout::TTCC_CONVERSION_PATTERN)));
270  appender->setName(_T("defaultAppender"));
271  root->addAppender(appender);
272  //Set the default threashold to be
273  root->setLevel(LOG4CXX_LEVEL_INFO);
274  }
275  LoggerPtr root = Logger::getRootLogger();
276 
277  fgQALogger = Logger::getLogger("QA");
278  fgUCMLogger = Logger::getLogger("UCM");
279  //#if 1
280  // Check the mandatory UCM appender
281  TString ucmenv = gSystem->Getenv("LOGGING");
282  if (ucmenv == "UCM" && gSystem->Getenv("JOBINDEX") && gSystem->Getenv("REQUESTID") ) {
283  StUCMAppenderPtr appender(new StUCMAppender(ucmenv.Data()));
284  appender->setLayout(new PatternLayout("%m"));
285  appender->setName(_T("UCM"));
286  fgUCMLogger->addAppender(appender);
287  StringMatchFilterPtr filter(new StringMatchFilter());
288  filter->setStringToMatch(_T("StageID="));
289  filter->setAcceptOnMatch(true);
290  appender->addFilter(filter);
291  appender->addFilter( DenyAllFilterPtr(new DenyAllFilter));
292 
293  //Set the default threashold to be
294  fgUCMLogger->setLevel(LOG4CXX_LEVEL_DEBUG);
295  }
296  // #endif
297  //Almost all QA messages are on the info level
298  NDC::push(_T(":"));
299 
300  mInstance = StarLoggerInit("BFC");
301  ((StLoggerManager *)mInstance)->SetStarOptionFilter(filter);
302  // if (gMessMgr) delete gMessMgr; gMessMgr = 0;
303  gMessMgr = mInstance;
304  // Set the ROOT ErrorHanlding via logger as well
305  // See: $ROOTSYS/include/TError.h
306  SetErrorHandler(Log4cxx4RootErrorHandler);
307 // Connect(gApplication,"Terminate(Int_t)",mInstance);
308  }
309  return mInstance;
310 }
311 //______________________________________________________________________________
312 std::ostringstream &StLoggerManager::Stream()
313 {
314  // return the stream allocated for the particular "fCurType"
315  // Create the new stream if there was none.
316  // ( I am too lazy to intreodcue the enumare here :-(()
317  switch (fCurType) {
318  case 'F': return fStreams[0];
319  case 'E': return fStreams[1];
320  case 'W': return fStreams[2];
321  case 'I': return fStreams[3];
322  case 'D': return fStreams[4];
323  case 'Q': return fStreams[5];
324  default: return fStreams[6];
325  };
326 }
327 
328 //______________________________________________________________________________
329 bool StLoggerManager::isDebugEnabled() const{ return fLogger->isDebugEnabled(); }
330 //______________________________________________________________________________
331 bool StLoggerManager::isWarnEnabled() const{ return fLogger->isWarnEnabled(); }
332 //______________________________________________________________________________
333 bool StLoggerManager::isErrorEnabled() const{ return fLogger->isErrorEnabled(); }
334 //______________________________________________________________________________
335 bool StLoggerManager::isInfoEnabled() const{ return fLogger->isInfoEnabled(); }
336 //______________________________________________________________________________
337 bool StLoggerManager::isFatalEnabled() const{ return fLogger->isFatalEnabled(); }
338 //______________________________________________________________________________
339 bool StLoggerManager::isEnabledFor() const{ return true; /*fLogger->isEnabledFor();*/ }
340 //______________________________________________________________________________
341 bool StLoggerManager::isQAInfoEnabled() const{ return fgQALogger? fgQALogger->isInfoEnabled():false; }
342 //______________________________________________________________________________
343 bool StLoggerManager::isUCMInfoEnabled() const{ return fgUCMLogger? fgUCMLogger->isInfoEnabled():false; }
344 //_____________________________________________________________________________
345 std::ostringstream& StLoggerManager::Message(const char* mess, const char* type,
346  const char* opt,const char *sourceFileName,int lineNumber) {
347 //
348 // Message declarator - creates a new message if mess is not empty,
349 // otherwise, prepares for << input.
350 //
351 //
352 // Instantiate an StMessage and place on the lists of known messages
353 // type =
354 // 'E' - error
355 // 'W' - warning
356 // 'I' - info
357 // 'D' - debug
358 // 'Q' - QA
359 // 'U' - UCM
360 //------------------------------
361 //
362 // opt =
363 // 'O' - stdout
364 // 'E' - stderr
365 // 'S' - skip "St"
366 // 'P' - plain output no decoration
367 // 'T' - print timestampt
368 //------------------------------
369  unsigned char typeChar = 'I';
370  if (type && type[0]) typeChar = type[0];
371  if (!opt) opt = "";
372  // size_t messSize = (mess && mess[0]) ? strlen(mess) : 0;
373 // *fCurType = typeChar;
374  fCurType = typeChar;
375  strcpy(fCurOpt,opt);
376 // if (tellp() > 0 ) *this << endm; // print out the previous line if any
377 
378  if (sourceFileName && sourceFileName[0] ) fSourceFileNames[LevelIndex(fCurType)] = sourceFileName;
379  else fSourceFileNames[LevelIndex(fCurType)].clear();
380  fLineNumbers[LevelIndex(fCurType)] = lineNumber;
381 
382  if (mess && std::char_traits<char>::length(mess) > 0) {
383  BuildMessage(mess, typeChar, opt, sourceFileName, lineNumber);
384  }
385 
386 // if (messSize > 0) *this << mess << endm; // print out the previous this message if present
387 // return *((StMessMgr*) this);
388  return Stream();
389 }
390 //_____________________________________________________________________________
391 void StLoggerManager::BuildMessage(const char* mess, unsigned char type,
392  const char* opt,const char *sourceFileName, int lineNumber) {
393 //
394 // Instantiate an StMessage and place on the lists of known messages
395 // type =
396 // 'F' - fatal
397 // 'E' - error
398 // 'W' - warning
399 // 'I' - info
400 // 'D' - debug
401 // 'Q' - QA
402 // 'U' - UCM
403 //------------------------------
404 //
405 // opt =
406 // 'O' - stdout
407 // 'E' - stderr
408 // 'S' - skip "St"
409 // 'P' - plain output no decoartion
410 // 'T' - print timestampt
411 //------------------------------
412 
413  if (!opt) opt = "";
414  PrintLogger(mess,type,opt,sourceFileName,lineNumber);
415 }
416 //_____________________________________________________________________________
417 void StLoggerManager::PrintLogger(const char* mess, unsigned char type,
418  const char* opt,const char *sourceFileName, int lineNumber)
419 {
420  if (!opt) opt = "";
421  unsigned char typeChar = 'I';
422  // if (type && type[0]) typeChar = type[0];
423  if (type) typeChar = type;
424  if (!(sourceFileName || fSourceFileNames[LevelIndex(typeChar)].empty() ) )
425  {
426  sourceFileName = fSourceFileNames[LevelIndex(typeChar)].c_str();
427  }
428 
429  if ( lineNumber == -1)
430  lineNumber = fLineNumbers[LevelIndex(typeChar)];
431  bool canPrint = true;
432  if (fAllowRepeat >= 0 ) {
433  // compare the current message with the buffered
434  if ( mess == fLastMessage ) {
435  fLastRepeatCounter++;
436  canPrint = (fAllowRepeat >= fLastRepeatCounter);
437  } else {
438  fLastRepeatCounter= 0;
439  fLastMessage = mess;
440  }
441  }
442  if (canPrint) {
443  if ( (mess == 0) || (mess[0] == 0)) mess = "."; // logger doesn't like the empty messages
444  // #if __GNUC__ > 3
445 #if (STAR_LOG4CXX_VERSION >= 10)
446  if (mColorEnabled)
447  {
448  TString Mess(mess);
449  switch (typeChar) {
450  case 'F': fLogger->fatal (_T(COLOR_PINK + Mess + COLOR_NORMAL),LocationInfo(sourceFileName,"",lineNumber)); break;
451  case 'E': fLogger->error (_T(COLOR_RED + Mess + COLOR_NORMAL),LocationInfo(sourceFileName,"",lineNumber)); break;
452  case 'W': fLogger->warn (_T(COLOR_YELLOW + Mess + COLOR_NORMAL),LocationInfo(sourceFileName,"",lineNumber)); break;
453  case 'I': fLogger->info (_T(COLOR_GREEN + Mess + COLOR_NORMAL),LocationInfo(sourceFileName,"",lineNumber)); break;
454  case 'D': fLogger->debug (_T(COLOR_BLUE + Mess + COLOR_NORMAL),LocationInfo(sourceFileName,"",lineNumber)); break;
455  case 'Q': fgQALogger->info (_T(COLOR_GREEN + Mess + COLOR_NORMAL),LocationInfo(sourceFileName,"",lineNumber)); break;
456  case 'U': fgUCMLogger->info(_T(COLOR_NORMAL + Mess + COLOR_NORMAL),LocationInfo(sourceFileName,"",lineNumber)); break;
457  default: fLogger->info (_T(COLOR_NORMAL + Mess + COLOR_NORMAL),LocationInfo(sourceFileName,"",lineNumber)); break;
458  };
459  } else
460 #endif
461  {
462  switch (typeChar) {
463  case 'F': fLogger->fatal (_T(mess),LocationInfo(sourceFileName,"",lineNumber)); break;
464  case 'E': fLogger->error (_T(mess),LocationInfo(sourceFileName,"",lineNumber)); break;
465  case 'W': fLogger->warn (_T(mess),LocationInfo(sourceFileName,"",lineNumber)); break;
466  case 'I': fLogger->info (_T(mess),LocationInfo(sourceFileName,"",lineNumber)); break;
467  case 'D': fLogger->debug (_T(mess),LocationInfo(sourceFileName,"",lineNumber)); break;
468  case 'Q': fgQALogger->info (_T(mess),LocationInfo(sourceFileName,"",lineNumber)); break;
469  case 'U': fgUCMLogger->info(_T(mess),LocationInfo(sourceFileName,"",lineNumber)); break;
470  default: fLogger->info (_T(mess),LocationInfo(sourceFileName,"",lineNumber)); break;
471  };
472  }
473  }
474  // seekp(0);
475  if (lineNumber != -1) { // restore the context
476  NDC::pop();
477  }
478 }
479 //_____________________________________________________________________________
480 void StLoggerManager::Print() {
481 //
482 // Empty the buffer into the current message and print it.
483 // If not currenty building a message, print the last one created.
484 //
485  string message = Stream().str();
486  BuildMessage(message.c_str(),fCurType,fCurOpt);
487 }
488 //_____________________________________________________________________________
489 int StLoggerManager::PrintList(messVec* list) {
490 //
491 // Print a list of messages from a messVec list.
492 //
493  _NO_IMPLEMENTATION_;
494  return -1;
495 }
496 //_____________________________________________________________________________
497 StMessage* StLoggerManager::FindMessage(const char* s1, const char* s2,
498  const char* s3, const char* s4, messVec* list) {
499  _NO_IMPLEMENTATION_;
500  return 0;
501 }
502 //_____________________________________________________________________________
503 messVec* StLoggerManager::FindMessageList(const char* s1, const char* s2,
504  const char* s3, const char* s4, messVec* list) {
505  _NO_IMPLEMENTATION_;
506  return 0;
507 }
508 //_____________________________________________________________________________
509 int StLoggerManager::RemoveMessage(StMessage* mess) {
510 _NO_IMPLEMENTATION_;
511  return 0;
512 }
513 //_____________________________________________________________________________
514 void StLoggerManager::Summary(size_t nTerms) {
515 //
516 // Output a summary of the messages printed so far.
517 // nTerms - number of tokens (text separated by spaces) to use in
518 // comparisons between messages (default is 1). Messages are
519 // compared only if they are of the same message type, and
520 // only the message string (not the message type) is included
521 // in the number of tokens compared. For example, Summary(0)
522 // would give the number of each type of message with no
523 // differentiation based on the message string.
524 //
525 _NO_IMPLEMENTATION_;
526 }
527 //_____________________________________________________________________________
528 void StLoggerManager::MemorySummary() {
529 //
530 // Output a summary of the memory usage of the message manager so far.
531 // Loops over all stored messages to calculate message sizes and overhead.
532 //
533  _NO_IMPLEMENTATION_;
534 }
535 //_____________________________________________________________________________
536 int StLoggerManager::AddType(const char* type, const char* text) {
537 //
538 // Add an additional message type. ListTypes() will return a list of all
539 // currently defined message types. AddType returns a integer which is zero
540 // if type has already been defined, otherwise returns the number of types
541 // defined (including the new one).
542 // type - a single character string which will represent the message type.
543 // text - a short charact string which will be printed with all messages
544 // of this type.
545 //
546  _NO_IMPLEMENTATION_;
547  return 0;
548 }
549 //_____________________________________________________________________________
550 void StLoggerManager::PrintInfo() {
551  fLogger->info("**************************************************************\n");
552  fLogger->info("* $Id: StLoggerManager.cxx,v 1.50 2013/07/23 20:03:05 dmitry Exp $\n");
553  // printf("* %s *\n",m_VersionCVS);
554  fLogger->info("**************************************************************\n");
555 }
556 
557 //_____________________________________________________________________________
558 
559 //_____________________________________________________________________________
560 //
561 // Info Messages:
562 //_____________________________________________________________________________
563 std::ostringstream& StLoggerManager::Info(const char* mess, const char* opt,const char *sourceFileName,int lineNumber)
564 { return Message(mess, "I", opt,sourceFileName,lineNumber);}
565 //_____________________________________________________________________________
566 int StLoggerManager::PrintInfos()
567 {
568  _NO_IMPLEMENTATION_;
569  return 0;
570  // return PrintList(messCollection[1]);
571 }
572 //_____________________________________________________________________________
573 const messVec* StLoggerManager::GetInfos()
574 {
575  _NO_IMPLEMENTATION_;
576  return 0;
577  // return (messCollection[1]);
578 }
579 //_____________________________________________________________________________
580 StMessage* StLoggerManager::FindInfo(const char* s1, const char* s2,
581  const char* s3, const char* s4)
582 {
583  _NO_IMPLEMENTATION_;
584  return 0;
585  // return FindMessage(s1,s2,s3,s4,messCollection[1]);
586 }
587 //_____________________________________________________________________________
588 messVec* StLoggerManager::FindInfoList(const char* s1, const char* s2,
589  const char* s3, const char* s4)
590 {
591  _NO_IMPLEMENTATION_;
592  return 0;
593  // return FindMessageList(s1,s2,s3,s4,messCollection[1]);
594 }
595 
596 //_____________________________________________________________________________
597 //
598 // Warning Messages:
599 //_____________________________________________________________________________
600 std::ostringstream& StLoggerManager::Warning(const char* mess, const char* opt,const char *sourceFileName,int lineNumber)
601 { return Message(mess, "W", opt,sourceFileName,lineNumber);}
602 //_____________________________________________________________________________
603 int StLoggerManager::PrintWarnings()
604 {
605  _NO_IMPLEMENTATION_;
606  return 0;
607  // return PrintList(messCollection[2]);
608 }
609 //_____________________________________________________________________________
610 const messVec* StLoggerManager::GetWarnings()
611 {
612  _NO_IMPLEMENTATION_;
613  return 0;
614  // return (messCollection[2]);
615 }
616 //_____________________________________________________________________________
617 StMessage* StLoggerManager::FindWarning(const char* s1, const char* s2,
618  const char* s3, const char* s4)
619 {
620  _NO_IMPLEMENTATION_;
621  return 0;
622  // return FindMessage(s1,s2,s3,s4,messCollection[2]);
623 }
624 //_____________________________________________________________________________
625 messVec* StLoggerManager::FindWarningList(const char* s1, const char* s2,
626  const char* s3, const char* s4)
627 {
628  _NO_IMPLEMENTATION_;
629  return 0;
630  // return FindMessageList(s1,s2,s3,s4,messCollection[2]);
631 }
632 
633 //_____________________________________________________________________________
634 //
635 // Error Messages:
636 //_____________________________________________________________________________
637 std::ostringstream& StLoggerManager::Error(const char* mess, const char* opt,const char *sourceFileName,int lineNumber)
638 { return Message(mess, "E", opt,sourceFileName,lineNumber);}
639 //_____________________________________________________________________________
640 int StLoggerManager::PrintErrors()
641 {
642  _NO_IMPLEMENTATION_;
643  return 0;
644  //return PrintList(messCollection[3]);
645 }
646 //_____________________________________________________________________________
647 const messVec* StLoggerManager::GetErrors()
648 {
649  _NO_IMPLEMENTATION_;
650  return 0;
651  // return (messCollection[3]);
652 }
653 //_____________________________________________________________________________
654 StMessage* StLoggerManager::FindError(const char* s1, const char* s2,
655  const char* s3, const char* s4)
656 {
657  _NO_IMPLEMENTATION_;
658  return 0;
659  // return FindMessage(s1,s2,s3,s4,messCollection[3]);
660 }
661 //_____________________________________________________________________________
662 messVec* StLoggerManager::FindErrorList(const char* s1, const char* s2,
663  const char* s3, const char* s4)
664 {
665  _NO_IMPLEMENTATION_;
666  return 0;
667  // return FindMessageList(s1,s2,s3,s4,messCollection[3]);
668 }
669 
670 //_____________________________________________________________________________
671 //
672 // Debug Messages:
673 //_____________________________________________________________________________
674 std::ostringstream& StLoggerManager::Debug(const char* mess, const char* opt,const char *sourceFileName,int lineNumber)
675 { return Message(mess, "D", opt,sourceFileName,lineNumber);}
676 //_____________________________________________________________________________
677 int StLoggerManager::PrintDebug()
678 {
679  _NO_IMPLEMENTATION_;
680  return 0;
681  // return PrintList(messCollection[4]);
682 }
683 //_____________________________________________________________________________
684 const messVec* StLoggerManager::GetDebugs()
685 {
686 _NO_IMPLEMENTATION_; return 0;
687 
688 // return (messCollection[4]);
689 }
690 //_____________________________________________________________________________
691 StMessage* StLoggerManager::FindDebug(const char* s1, const char* s2,
692  const char* s3, const char* s4)
693 {
694  _NO_IMPLEMENTATION_; return 0;
695  // return FindMessage(s1,s2,s3,s4,messCollection[4]);
696 }
697 //_____________________________________________________________________________
698 messVec* StLoggerManager::FindDebugList(const char* s1, const char* s2,
699  const char* s3, const char* s4)
700 {
701 _NO_IMPLEMENTATION_; return 0;
702  // return FindMessageList(s1,s2,s3,s4,messCollection[4]);
703 }
704 
705 //_____________________________________________________________________________
706 //
707 // QAInfo Messages:
708 //_____________________________________________________________________________
709 std::ostringstream& StLoggerManager::QAInfo(const char* mess, const char* opt,const char *sourceFileName,int lineNumber)
710 { return Message(mess, "Q", opt,sourceFileName,lineNumber);}
711 //_____________________________________________________________________________
712 //
713 // UCMInfo Messages:
714 //_____________________________________________________________________________
715 std::ostringstream& StLoggerManager::UCMInfo(const char* mess, const char* opt,const char *sourceFileName,int lineNumber)
716 { return Message(mess, "U", opt,sourceFileName,lineNumber);}
717 //_____________________________________________________________________________
718 void StLoggerManager::IgnoreRepeats()
719 {
720  AllowRepeats(0);
721 }
722 
723 //_____________________________________________________________________________
724 void StLoggerManager::AllowRepeats(int nRepeats)
725 {
726  // fAllowRepeat > 0 the max number to repeat one and the same message
727  // == 0 the repating is not allowed
728  // == -1 there is no limit;
729  fAllowRepeat = nRepeats;
730  fLastRepeatCounter = 0;
731  StarOptionFilterPtr& filter = ((StLoggerManager *)mInstance)->GetStarOptionFilter();
732  if (filter != 0 )
733  filter->setRepeatCounterOption(nRepeats);
734 
735 }
736 
737 
738 //_____________________________________________________________________________
739 void StLoggerManager::AllowRepeats()
740 {
741  AllowRepeats(-1);
742 }
743 
744 
745 //_____________________________________________________________________________
746 int StLoggerManager::PrintQAInfo()
747 {
748 _NO_IMPLEMENTATION_; return 0;
749  // return PrintList(messCollection[5]);
750 }
751 //_____________________________________________________________________________
752 const messVec* StLoggerManager::GetQAInfos()
753 {
754 _NO_IMPLEMENTATION_; return 0;
755  // return (messCollection[5]);
756 }
757 //_____________________________________________________________________________
758 StMessage* StLoggerManager::FindQAInfo(const char* s1, const char* s2,
759  const char* s3, const char* s4)
760 {
761 _NO_IMPLEMENTATION_; return 0;
762  // return FindMessage(s1,s2,s3,s4,messCollection[5]);
763 }
764 //_____________________________________________________________________________
765 messVec* StLoggerManager::FindQAInfoList(const char* s1, const char* s2,
766  const char* s3, const char* s4)
767 {
768 _NO_IMPLEMENTATION_; return 0;
769  // return FindMessageList(s1,s2,s3,s4,messCollection[5]);
770 }
771 
772 //_____________________________________________________________________________
773 int StLoggerManager::PrintUCMInfo()
774 {
775 _NO_IMPLEMENTATION_; return 0;
776  // return PrintList(messCollection[5]);
777 }
778 //_____________________________________________________________________________
779 const messVec* StLoggerManager::GetUCMInfos()
780 {
781 _NO_IMPLEMENTATION_; return 0;
782  // return (messCollection[5]);
783 }
784 //_____________________________________________________________________________
785 StMessage* StLoggerManager::FindUCMInfo(const char* s1, const char* s2,
786  const char* s3, const char* s4)
787 {
788 _NO_IMPLEMENTATION_; return 0;
789  // return FindMessage(s1,s2,s3,s4,messCollection[5]);
790 }
791 //_____________________________________________________________________________
792 messVec* StLoggerManager::FindUCMInfoList(const char* s1, const char* s2,
793  const char* s3, const char* s4)
794 {
795 _NO_IMPLEMENTATION_; return 0;
796  // return FindMessageList(s1,s2,s3,s4,messCollection[5]);
797 }
798 
799 //_____________________________________________________________________________
800 std::ostringstream& StLoggerManager::Fatal(const char* mess, const char* opt,const char *sourceFileName, int lineNumber)
801 { return Message(mess,"F",opt,sourceFileName,lineNumber);}
802 
803 // "As is" Messages:
804 //_____________________________________________________________________________
805 std::ostringstream& StLoggerManager::out(const char* mess)
806 {return Message(mess,"I","OP-");}
807 //_____________________________________________________________________________
808 std::ostringstream& StLoggerManager::err(const char* mess)
809 {return Message(mess,"E","EP-");}
810 
811 
812 
813 // Dummy methods
814 //_____________________________________________________________________________
815 int StLoggerManager::PrintAll()
816 {
817 _NO_IMPLEMENTATION_; return 0;
818  // return PrintList(&messList);
819 }
820 
821 //_____________________________________________________________________________
822 const messVec* StLoggerManager::GetAll()
823 {
824 _NO_IMPLEMENTATION_; return 0;
825 
826 // return (&messList);
827 }
828 
829 //_____________________________________________________________________________
830 int StLoggerManager::RemoveMessage(const char* s1, const char* s2,
831  const char* s3, const char* s4)
832 { return RemoveMessage(FindMessage(s1,s2,s3,s4)); }
833 
834 //_____________________________________________________________________________
835 void StLoggerManager::SetLimit(const char* str, int n)
836 {
837  if (str && str[0] && str[1]) {
838  LoggerPtr root = Logger::getRootLogger();
839  AppenderPtr defaultAppender = root->getAppender(_T("defaultAppender"));
840  if (defaultAppender != 0){
841  StarOptionFilterPtr filter = new StarOptionFilter();
842  filter->setRepeatCounterOption(n);
843  filter->setOption(_T("StringToCount"),str);
844 // cout << endl<< "-- Appedner " << defaultAppender->getName() << " -* -* -* -* -* -* -* -* "
845 // << str << "n = " << n << " -* -* -* -* -* -* -* -* " << endl << endl;
846  defaultAppender->addFilter(filter);
847  }
848  }
849 
850 // messCounter->SetLimit(str,n);
851 }
852 //_____________________________________________________________________________
853 int StLoggerManager::GetLimit(const char* str)
854 {
855 _NO_IMPLEMENTATION_; return -1;
856  // return messCounter->GetLimit(str);
857 }
858 //_____________________________________________________________________________
859 void StLoggerManager::ListLimits()
860 {
861 _NO_IMPLEMENTATION_;
862 // messCounter->ListLimits();
863 }
864 //_____________________________________________________________________________
865 void StLoggerManager::Close()
866 {
867  // Close the messenger streams
868  // Close the QA-related appenders to flush its buffers
869  if (fgQALogger) fgQALogger->closeNestedAppenders();
870  if (fgUCMLogger) fgUCMLogger->closeNestedAppenders();
871 }
872 //_____________________________________________________________________________
873 void StLoggerManager::RemoveLimit(const char* str)
874 { SetLimit(str,-1); }
875 //_____________________________________________________________________________
876 void StLoggerManager::SwitchOff(const char* str)
877 { SetLimit(str,0); }
878 //_____________________________________________________________________________
879 void StLoggerManager::SwitchOn(const char* str)
880 { RemoveLimit(str); }
881 //_____________________________________________________________________________
882 void StLoggerManager::FixOn(const char* str)
883 { SetLimit(str,-5); }
884 //_____________________________________________________________________________
885 void StLoggerManager::NoLimits()
886 {
887 _NO_IMPLEMENTATION_;
888 // messCounter->NoLimits();
889 }
890 //_____________________________________________________________________________
891 void StLoggerManager::MemoryOn()
892 {
893 _NO_IMPLEMENTATION_;
894 // remember=1;
895 }
896 //_____________________________________________________________________________
897 void StLoggerManager::MemoryOff()
898 {
899 _NO_IMPLEMENTATION_;
900 // remember=0;
901 }
902 //_____________________________________________________________________________
903 int StLoggerManager::ListTypes()
904 {
905 _NO_IMPLEMENTATION_; return 5;
906 // return messTypeList->ListTypes();
907 }
908 
909 //_____________________________________________________________________________
910 void StLoggerManager::SetLevel(Int_t level)
911 {
912  // Map STAR level to the logger level and set the logger level
913  switch (level) {
914  case kFatal:
915  fLogger->setLevel(LOG4CXX_LEVEL_FATAL);
916  break;
917  case kError:
918  fLogger->setLevel(LOG4CXX_LEVEL_ERROR);
919  break;
920  case kWarning:
921  fLogger->setLevel(LOG4CXX_LEVEL_WARN);
922  break;
923  case kInfo:
924  fLogger->setLevel(LOG4CXX_LEVEL_INFO);
925  break;
926  case kAll:
927  case kDebug:
928  case kDebug2:
929  fLogger->setLevel(LOG4CXX_LEVEL_DEBUG);
930  break;
931  case kDefault:
932  // restore the default level (defined the XML configuration if present)
933  fLogger->setLevel(fDefaultLevel);
934  break;
935  default:
936  fLogger->setLevel(LOG4CXX_LEVEL_DEBUG);
937  break;
938  };
939 }
940 //_____________________________________________________________________________
941 Int_t StLoggerManager::GetLevel(Int_t) const
942 {
943  // Map the current logger level to the STAR one
944 #if 0
945  const LevelPtr &level = fLogger->getLevel();
946  if (level == &LOG4CXX_LEVEL_DEBUG) return kDebug;
947  else if (level == &LOG4CXX_LEVEL_FATAL) return kFatal;
948  else if (level == &LOG4CXX_LEVEL_ERROR) return kError;
949  else if (level == &LOG4CXX_LEVEL_WARN ) return kWarning;
950  else if (level == &LOG4CXX_LEVEL_INFO ) return kInfo;
951 #endif
952  return kAll;
953 }
954 
955 //_____________________________________________________________________________
956 void StLoggerManager:: DestroyInstance()
957 {
958  if (mInstance) {
959  // There is no method to chech ref. do it blindly.
960  // fgQALogger->releaseRef(); fgQALogger->releaseRef();
961  fgUCMLogger->releaseRef();
962  // fgUCMLogger->releaseRef();
963  // Logger::getRootLogger()->releaseRef();
964  // StMessMgr *thisPtr = mInstance;
965  mInstance = 0; gMessMgr = 0;
966  // delete thisPtr;
967  }
968 }
969 #if 0
970 //_____________________________________________________________________________
971 const char *GetName()
972 {
973  // Returns the name of the current logger
974  CurrentMessager()
975 }
976 #endif
977 
978 //_____________________________________________________________________________
979  // Instantiate the (singleton) class upon loading
980  //
981 // static StMessMgr* temp=StLoggerManager::Instance();
982 // std::ostringstream& gMess = *(StMessMgr *)StLoggerManager::Instance();
983 
984 //_____________________________________________________________________________
985 // $Id: StLoggerManager.cxx,v 1.50 2013/07/23 20:03:05 dmitry Exp $
986 // $Log: StLoggerManager.cxx,v $
987 // Revision 1.50 2013/07/23 20:03:05 dmitry
988 // missing backwards compatibility feature restored
989 //
990 // Revision 1.49 2012/12/04 15:31:03 jeromel
991 // Replaced GNUC by STAR_LOG4CXX_VERSION for consistency, comment if 1
992 //
993 // Revision 1.48 2012/11/26 23:02:17 fisyak
994 // Add color by demand for __GNUC__ > 3
995 //
996 // Revision 1.47 2012/11/26 12:26:18 jeromel
997 // Undo (again!)
998 //
999 // Revision 1.45 2012/10/05 17:16:33 jeromel
1000 // [no real change, trim trailing spaces]
1001 //
1002 // Revision 1.44 2012/10/05 17:14:32 jeromel
1003 // Made no color the default (set yes to Logger.color to yes if one wants to enable)
1004 //
1005 // For now, restored no color as fLogger->XXX does not take TSring but char * under
1006 // older log4cxx version (compilation would break). Other solution to be found later.
1007 //
1008 // A side note that a xml based setting for colors (including which color goes to
1009 // what level of messages) is likely the proper approach to avoid mixing config
1010 // approach.
1011 //
1012 // Revision 1.43 2012/10/05 14:16:48 fisyak
1013 // Change default from color => non color
1014 //
1015 // Revision 1.42 2012/10/04 23:32:29 fisyak
1016 // allow to switch off color by putting in .rootrc line with Logger.Color no
1017 //
1018 // Revision 1.41 2012/10/04 15:44:20 fisyak
1019 // Add colors
1020 //
1021 // Revision 1.40 2012/06/11 14:58:55 fisyak
1022 // std namespace
1023 //
1024 // Revision 1.39 2010/04/27 21:31:44 fine
1025 // remove the logger destruction side effect
1026 //
1027 // Revision 1.38 2010/04/23 22:39:11 fine
1028 // RT #1911. Make interface log4cxx compliant. Remove the dtor dead-lock and add post-mortim clean up
1029 //
1030 // Revision 1.37 2009/09/09 00:05:13 fine
1031 // Merge log4cxx version 9 and 10
1032 //
1033 // Revision 1.36 2009/06/23 19:37:33 fine
1034 // replace QA logger with the dedicated UCM one
1035 //
1036 // Revision 1.35 2009/06/23 19:21:21 fine
1037 // Add the mandatory UCM filters
1038 //
1039 // Revision 1.34 2009/06/22 22:36:01 fine
1040 // Add the new dedicated UCM logger, It should force the recompilation of many STAR packages
1041 //
1042 // Revision 1.33 2009/06/22 01:12:08 fine
1043 // Disable the default UCM. Use log4j.xml instead, for the time being
1044 //
1045 // Revision 1.32 2009/06/19 22:18:36 fine
1046 // pick the technology from the LOGGING var
1047 //
1048 // Revision 1.31 2009/06/17 22:11:59 fine
1049 // Add UCM appender to the StStarLogger and activate it as soon as the env LOGGING is set to UCM
1050 //
1051 // Revision 1.30 2008/05/19 15:08:20 fine
1052 // allow complex formating with several logger stream concurrently. Thanx Victor
1053 //
1054 // Revision 1.29 2008/05/15 23:40:23 fine
1055 // Change the abstarct class return type to separate the different STAR streams
1056 //
1057 // Revision 1.28 2007/08/08 20:50:22 fine
1058 // Fix bug: some messages submitted via the old interface were lost
1059 //
1060 // Revision 1.27 2007/08/03 21:34:51 fine
1061 // fix StStarLogger for Sl 4.4
1062 //
1063 // Revision 1.26 2007/02/13 22:07:26 perev
1064 // Add the lost part of the ROOT message - location
1065 //
1066 // Revision 1.25 2007/01/30 20:48:57 fine
1067 // Make the deault level for all loggers INFO
1068 //
1069 // Revision 1.24 2007/01/30 19:25:51 fine
1070 // Set the deafult level for QA to b INFO
1071 //
1072 // Revision 1.23 2007/01/25 18:36:38 fine
1073 // Acivate logger level StMaker level run-time adjustment
1074 //
1075 // Revision 1.22 2007/01/23 22:27:14 fine
1076 // Set the dwefault logger level to WARN
1077 //
1078 // Revision 1.21 2006/07/01 01:19:17 fine
1079 // Add new jiob tracking option code
1080 //
1081 // Revision 1.20 2006/06/05 00:21:40 fine
1082 // class the new StMessMgr method to flush the logger buffers
1083 //
1084 // Revision 1.19 2006/05/19 21:42:30 fine
1085 // remove the debug print outs
1086 //
1087 // Revision 1.18 2005/12/20 20:51:15 fine
1088 // fix typo
1089 //
1090 // Revision 1.17 2005/10/10 20:24:17 fine
1091 // Bug fix: add the brackets around the if statements
1092 //
1093 // Revision 1.16 2005/09/14 15:35:25 fine
1094 // Clean up the code
1095 //
1096 // Revision 1.15 2005/08/21 20:20:18 perev
1097 // fix typo in comment
1098 //
1099 // Revision 1.14 2005/08/19 21:01:05 fine
1100 // Manage the ROOT messages with the StarLogger
1101 //
1102 // Revision 1.13 2005/08/05 19:39:14 fine
1103 // Make use of the DOM Configurator instead of PropertyConfigurator
1104 //
1105 // Revision 1.12 2005/03/07 23:17:09 fine
1106 // Fix a bug to allow mnay logger insatnces to print out without any mess
1107 //
1108 // Revision 1.11 2004/11/15 17:25:59 fine
1109 // Make Star filer workign properly
1110 //
1111 // Revision 1.10 2004/11/13 00:28:16 fine
1112 // teach StarOption filter to count the messages
1113 //
1114 // Revision 1.9 2004/11/05 20:24:43 fine
1115 // Remove some redundant lines, clean up
1116 //
1117 // Revision 1.8 2004/11/05 20:24:00 fine
1118 // Replace the obsolete StLoggerManager::Instance with tMessMgr::CurrentMessager()
1119 //
1120 // Revision 1.7 2004/11/03 16:39:32 fine
1121 // add extra method to checl STAR QA info logger
1122 //
1123 // Revision 1.6 2004/11/03 01:33:22 fine
1124 // add the implemantions of the new based methods and clean up
1125 //
1126 // Revision 1.5 2004/09/16 00:13:05 fine
1127 // remove the implict StStarLogger object. We should give log4cxx a chance to complete the intialization
1128 //
1129 // Revision 1.4 2004/05/11 23:48:19 fine
1130 // update the default logger pattern
1131 //
1132 // Revision 1.3 2004/05/11 23:21:58 fine
1133 // add the default logger description
1134 //
1135 // Revision 1.2 2004/05/11 22:42:27 fine
1136 // Add the default configurator
1137 //
1138 // Revision 1.1 2004/05/11 20:58:48 fine
1139 // first implemantation of the abstarct STAR messeger via log4cxx package
1140 //