#include <MsgService.h>
Public Member Functions | |
| ~MsgService () | |
| bool | IsActive (const char *str_name, Msg::LogLevel_t lvl) |
| void | AddCatStream (const char *fileName, const char *streamName, Msg::LogLevel_t lvl) |
| MsgStream * | GetStream (const char *name) |
| void | PrintStatistics () |
| void | PrintStatistics (std::ostream &os) |
| void | SetDefaultFormat (int fmt, int level=99) |
| void | SetCurrentRunSnarl (int run, int snarl) |
| void | GetCurrentRunSnarl (int &run, int &snarl) |
Static Public Member Functions | |
| MsgService * | Instance () |
| void | StackTrace (const char *stream, Msg::LogLevel_t lvl, int depth=100, int ignore=0) |
| void | SetGlobalLevel () |
Private Member Functions | |
| MsgService () | |
| const char * | GetTmpCatFileName (const char *streamName, int lvl) |
| MsgStream * | CreateStream (const char *name) |
Private Attributes | |
| Msg::LogLevel_t | fDefaultLogLevel |
| char | fDefaultOStream [Msg::kNLogLevel][64] |
| int | fDefaultFormat [Msg::kNLogLevel] |
| std::map< std::string, MsgStream * > | fMsgStreamTable |
| std::vector< MsgCatStream > | fMsgCatList |
| int | fCurrentRun |
| int | fCurrentSnarl |
Static Private Attributes | |
| MsgService * | fInstance = 0 |
| Msg::LogLevel_t | fsGlobalLogLevel = Msg::kInfo |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const MsgService &m) |
|
|
Definition at line 81 of file MsgService.cxx. References fMsgCatList, and fMsgStreamTable. 00082 {
00083 //======================================================================
00084 // Purpose: Clean up after the message service - for now this includes:
00085 // - Closing all output streams
00086 // - Taking care of concatenated stream output
00087 //======================================================================
00088
00089 // Close all output message streams
00090 map<std::string,MsgStream*>::iterator mend(fMsgStreamTable.end());
00091 for (map<std::string,MsgStream*>::iterator itr = fMsgStreamTable.begin();
00092 itr != mend;
00093 ++itr) {
00094 itr->second->Close();
00095 delete itr->second;
00096 }
00097
00098 // Take care of any streams that need to be concatenated
00099 vector<MsgCatStream>::iterator vend(fMsgCatList.end());
00100 for (vector<MsgCatStream>::iterator iter = fMsgCatList.begin();
00101 iter != vend;
00102 ++iter) {
00103 iter->DoConcatenation();
00104 }
00105 }
|
|
|
Definition at line 362 of file MsgService.cxx. References fCurrentRun, fCurrentSnarl, fDefaultFormat, fDefaultLogLevel, fDefaultOStream, and fsGlobalLogLevel. Referenced by Instance(). 00363 {
00364 //======================================================================
00365 // Purpose: Create and initialize the message service
00366 //======================================================================
00367 // Set the default log level for all streams
00368 fDefaultLogLevel = Msg::kInfo;
00369
00370 // Set the default output streams
00371 strcpy(fDefaultOStream[Msg::kVerbose], "cerr");
00372 strcpy(fDefaultOStream[Msg::kDebug], "cerr");
00373 strcpy(fDefaultOStream[Msg::kSynopsis],"cout");
00374 strcpy(fDefaultOStream[Msg::kInfo], "cout");
00375 strcpy(fDefaultOStream[4], "cout"); // not yet used.
00376 strcpy(fDefaultOStream[Msg::kWarning], "cerr");
00377 strcpy(fDefaultOStream[Msg::kError], "cerr");
00378 strcpy(fDefaultOStream[Msg::kFatal], "cerr");
00379
00380 // Set the default formats
00381 fDefaultFormat[Msg::kVerbose] =
00382 Msg::kPriority + Msg::kName +
00383 Msg::kFile + Msg::kLine;
00384 fDefaultFormat[Msg::kDebug] =
00385 Msg::kPriority + Msg::kName +
00386 Msg::kFile + Msg::kLine;
00387 fDefaultFormat[Msg::kSynopsis] = 0;
00388 fDefaultFormat[Msg::kInfo] = 0;
00389 fDefaultFormat[Msg::kWarning] =
00390 Msg::kPriority + Msg::kName +
00391 Msg::kFile + Msg::kCVSId + Msg::kLine;
00392 fDefaultFormat[Msg::kError] =
00393 Msg::kPriority + Msg::kName + Msg::kTime +
00394 Msg::kFile + Msg::kCVSId + Msg::kLine;
00395 fDefaultFormat[Msg::kFatal] =
00396 Msg::kPriority + Msg::kName + Msg::kTime +
00397 Msg::kFile + Msg::kCVSId + Msg::kLine;
00398
00399 fsGlobalLogLevel = fDefaultLogLevel;
00400
00401 fCurrentRun = -1;
00402 fCurrentSnarl = -1;
00403 }
|
|
||||||||||||||||
|
Definition at line 280 of file MsgService.cxx. References MsgCatStream::AddFileToList(), MsgStream::AttachOStream(), fMsgCatList, GetStream(), and GetTmpCatFileName(). Referenced by MsgServiceValidate::TestMsgService(). 00283 {
00284 //======================================================================
00285 // Purpose: Add a stream to the list that will get concatenated to
00286 // the file fileName
00287 //
00288 // Inputs: fileName - The file name where the concat'ed output goes
00289 // streamName - The stream whose output should be concat'ed
00290 // lvl - The threshold to apply to the stream
00291 //======================================================================
00292
00293 // Attach a temporary file to the message stream
00294 const char *tmpFileName = GetTmpCatFileName(streamName, lvl);
00295 this->GetStream(streamName)->AttachOStream(lvl, tmpFileName);
00296
00297 // Add this temporary file to the list of files that should get
00298 // concatenated together
00299
00300 // Check if this concatenated file already exists
00301 MsgCatStream *catStream = 0;
00302 for (vector<MsgCatStream>::iterator iter = fMsgCatList.begin();
00303 iter != fMsgCatList.end();
00304 ++iter) {
00305 if (strcmp((*iter).GetOutputFileName(), fileName)==0) {
00306 catStream = &(*iter);
00307 break;
00308 }
00309 }
00310 if (catStream == 0) {
00311 // Doesn't exist -- create it and insert in list
00312 catStream = new MsgCatStream(fileName);
00313 catStream->AddFileToList(tmpFileName);
00314 fMsgCatList.push_back(*catStream);
00315 delete catStream;
00316 }
00317 else {
00318 // Already exists -- just add to it
00319 catStream->AddFileToList(tmpFileName);
00320 }
00321 }
|
|
|
Definition at line 325 of file MsgService.cxx. References MsgStream::AttachOStream(), fDefaultFormat, fDefaultLogLevel, fDefaultOStream, fMsgStreamTable, MsgStream::SetFormat(), SetGlobalLevel(), and MsgStream::SetLogLevel(). 00326 {
00327 //======================================================================
00328 // Purpose: Create and configure a new message stream. If the stream
00329 // already exists, just return the existing stream
00330 //
00331 // Inputs: name - The name of the stream requested
00332 //
00333 // Returns: The message stream with this name
00334 //======================================================================
00335 std::string msgName(name);
00336 MsgStream *msgStream;
00337
00338 // Test if the stream already exists
00339 if ((msgStream = fMsgStreamTable[msgName]) != 0) {
00340 return msgStream;
00341 }
00342
00343 // If not then create it using the defaults
00344 msgStream = new MsgStream(name); // Ownership is given away --
00345 assert(msgStream);
00346
00347 // Configure
00348 msgStream->SetLogLevel(fDefaultLogLevel);
00349 for (Msg::LogLevel_t lvl=0; lvl<Msg::kNLogLevel; ++lvl) {
00350 msgStream->AttachOStream(lvl, fDefaultOStream[lvl]);
00351 msgStream->SetFormat(lvl, fDefaultFormat[lvl]);
00352 }
00353 fMsgStreamTable[msgName] = msgStream;
00354
00355 MsgService::SetGlobalLevel(); // Reset the global level now that there's a new stream to watch.
00356
00357 return msgStream;
00358 }
|
|
||||||||||||
|
Definition at line 68 of file MsgService.h. References run(). Referenced by JobCEnv::ContinueRun(), and MsgStream::operator()(). 00068 { run = fCurrentRun; snarl = fCurrentSnarl; };
|
|
|
||||||||||||
|
Definition at line 407 of file MsgService.cxx. Referenced by AddCatStream(). 00409 {
00410 //======================================================================
00411 // Purpose: Create a unique temporary filename for a stream of a given
00412 // log level
00413 //
00414 // Inputs: streamName - the name of the stream requesting the tmp file
00415 // lvl - the threshold for this file to accept messages
00416 //
00417 // Returns: A temporary file name
00418 //======================================================================
00419 static char fileName[256];
00420 sprintf(fileName, ".%s.%d.%d", streamName, lvl, getpid());
00421 return fileName;
00422 }
|
|
|
||||||||||||
|
|
Definition at line 436 of file MsgService.cxx. References fMsgStreamTable, and MsgStream::PrintStatistics(). 00437 {
00438 //======================================================================
00439 // Purpose: Print usage statistics for the message service
00440 //
00441 // Inputs: os - the output stream to print to
00442 //======================================================================
00443
00444 // Copy the map to a container we can sort
00445 list<pair<std::string, MsgStream*> > streamList;
00446 map<std::string, MsgStream*>::iterator mend(fMsgStreamTable.end());
00447 for (map<std::string, MsgStream*>::iterator itr = fMsgStreamTable.begin();
00448 itr != mend;
00449 ++itr) {
00450 // Push the key-value pair from the map into the list
00451 streamList.push_back(*itr);
00452 }
00453 streamList.sort();
00454
00455 // Print the headers - note this has to stay in sync with MsgStream's
00456 // format for printing statistics
00457 os << "======================= "
00458 << "Message Service Usage Statistics"
00459 << " =======================\n";
00460 os << " Stream "
00461 << "File "
00462 << "Print Counts\n";
00463 os << " ------ "
00464 << "------------------------ "
00465 << "-----------------------------------------------\n";
00466
00467 list<pair<std::string, MsgStream*> >::iterator lend(streamList.end());
00468 for (list<pair<std::string, MsgStream*> >::iterator itr = streamList.begin();
00469 itr != lend;
00470 ++itr) {
00471 itr->second->PrintStatistics(os);
00472 }
00473
00474 os << "========================"
00475 << "================================"
00476 << "========================\n";
00477 }
|
|
|
Definition at line 426 of file MsgService.cxx. Referenced by printStatistics(), JobCMsgModule::Stats(), and MsgServiceValidate::TestMsgService(). 00427 {
00428 //======================================================================
00429 // Purpose: Print usage statistics for the message service
00430 //======================================================================
00431 this->PrintStatistics(cerr);
00432 }
|
|
||||||||||||
|
Definition at line 67 of file MsgService.h. Referenced by RerootToTruthModule::Get(). 00067 { fCurrentRun = run; fCurrentSnarl = snarl; };
|
|
||||||||||||
|
Definition at line 109 of file MsgService.cxx. References fDefaultFormat. Referenced by JobCMsgModule::SetDefaultFormat(). 00110 {
00111 //=======================================================================
00112 // Add flags specified by fmt to the defaults for the log level "level"
00113 // Only affects streams created after this call, ie. action is not
00114 // retroactive. Use "level" which is out of range to affect all
00115 // printing levels
00116 //=======================================================================
00117 if ((level>=0) && (level<Msg::kNLogLevel)) {
00118 if((fmt & Msg::kFgColorMask)) fDefaultFormat[level] &=(~Msg::kFgColorMask); // Reset FG color if being set
00119 if((fmt & Msg::kBgColorMask)) fDefaultFormat[level] &=(~Msg::kBgColorMask); // Reset BG color if being set
00120 fDefaultFormat[level] |= fmt;
00121 }
00122 else {
00123 for (int lvl=0; lvl<Msg::kNLogLevel; ++lvl) {
00124 if((fmt & Msg::kFgColorMask)) fDefaultFormat[lvl] &=(~Msg::kFgColorMask); // Reset FG color if being set
00125 if((fmt & Msg::kBgColorMask)) fDefaultFormat[lvl] &=(~Msg::kBgColorMask); // Reset BG color if being set
00126 fDefaultFormat[lvl] |= fmt;
00127 }
00128 }
00129
00130 }
|
|
|
Search all the current streams. Find the one with the lowest print setting and use that as the global setting. Definition at line 480 of file MsgService.cxx. References fMsgStreamTable, fsGlobalLogLevel, MsgStream::GetLogLevel(), Instance(), and s(). Referenced by CreateStream(), and MsgStream::SetLogLevel(). 00481 {
00486 fsGlobalLogLevel = Msg::kFatal;
00487
00488 MsgService* self = MsgService::Instance();
00489 std::map<std::string,MsgStream*>::iterator it = self->fMsgStreamTable.begin();
00490 for(it = self->fMsgStreamTable.begin(); it != self->fMsgStreamTable.end(); it++ ) {
00491 MsgStream* s = it->second;
00492 if(s) {
00493 if(s->GetLogLevel() < fsGlobalLogLevel) fsGlobalLogLevel = s->GetLogLevel();
00494 }
00495 }
00496 }
|
|
||||||||||||||||||||
|
Stack Trace Two versions of the code here. The first can be used on non-linux systems, or whenever the main code fails. It just wraps the ROOT stack trace (which is uglier). The second is the custom version. NJT 3/3/2005 Definition at line 197 of file MsgService.cxx. References Instance(), IsActive(), and s(). Referenced by MsgStream::operator()(). 00198 {
00199 if(!MsgService::Instance()->IsActive(stream,lvl)) return;
00200 MsgStream& s = *((MsgService::Instance())->GetStream(stream));
00201
00202 void *trace[10]; //only care about last 7 functions (3 taken with tracing support)
00203 size_t size;
00204
00205 size_t i;
00206 char cmd[512];
00207
00208 size = backtrace (trace, 10);
00209
00210 // Need -rdynamic gcc (linker) flag for this to work
00211 // but the result is not pretty.
00212 //char **strings = NULL;
00213 //strings = backtrace_symbols (trace, size);
00214 //for (i = 2; i < size; i++){ //skip useless functions
00215 // printf("going(%02d) [%s]\n",i-2,strings[i]);
00216 //free(strings);
00217
00218 size_t start = 1 + ignore; // skip usless functions
00219 size_t end = depth + start; // Set depth.
00220 if(end>size) end=size;
00221
00222 for (i = start; i < end; i++){ //skip useless functions
00223 // printf("going(%02d) [%s]\n",i-2,strings[i]);
00224
00225 unsigned long addr = (unsigned long) trace[i];
00226 Dl_info info;
00227 if(dladdr(trace[i], &info) && info.dli_fname && info.dli_fname[0]) {
00228 const char *libname = info.dli_fname;
00229 const char *symname = (info.dli_sname && info.dli_sname[0])
00230 ? info.dli_sname : "unknown";
00231 unsigned long libaddr = (unsigned long) info.dli_fbase;
00232 //unsigned long symaddr = (unsigned long) info.dli_saddr;
00233 unsigned long offset = (addr >= libaddr) ? addr - libaddr :
00234 libaddr - addr;
00235
00236 char linestr[1024];
00237 sprintf(linestr,"addr:0x%lx",addr); // Default: dump the address raw.
00238
00239 sprintf(cmd,"addr2line -e %s 0x%016lx 2> /dev/null", libname, offset);
00240 if (FILE *pf = ::popen(cmd, "r")) {
00241 if (fgets(linestr, 1024, pf)) {
00242 linestr[strlen(linestr)-1] = 0; // remove trailing \n
00243 }
00244 ::pclose(pf);
00245 }
00246
00247 char funcname[1024];
00248 strcpy(funcname,symname);
00249 sprintf(cmd,"c++filt %s 2>/dev/null", symname);
00250 if (FILE *pf = ::popen(cmd, "r")) {
00251 if (fgets(funcname, 1024, pf)) {
00252 funcname[strlen(funcname)-1] = 0; // remove trailing \n
00253 }
00254 ::pclose(pf);
00255 }
00256
00257 // Strip off most of the path.
00258 int slashes = 0;
00259 for(char* c = linestr+strlen(linestr)-1; c>linestr; c--) {
00260 if( (*c) == '/' ) slashes++;
00261 if(slashes==2) {
00262 char tmp[1024];
00263 strcpy(tmp,c+1);
00264 strcpy(linestr,tmp);
00265 break;
00266 }
00267 }
00268
00269 // Write out the line.
00270 s << " [" << i-start << "] " << funcname << " @ " << linestr << endl;
00271 //printf("%s @ %s\n",funcname,linestr);
00272 }
00273
00274 }
00275 }
|
|
||||||||||||
|
Definition at line 31 of file MsgService.cxx. 00032 {
00033 //======================================================================
00034 // Purpose: Print out infomation about the message service
00035 //
00036 // Inputs os - the output stream to print to
00037 // m - the message service to report on
00038 //
00039 // Returns: The stream printed to
00040 //======================================================================
00041 int i;
00042 static const MsgFormat hexfmt("8x");
00043
00044 os << "***** MsgService *******************"
00045 << "************************************\n";
00046 os << " Defaults:\n";
00047 os << " Loglevel: " << (int)m.fDefaultLogLevel << "\n";
00048 for (i = 0; i<Msg::kNLogLevel; ++i) {
00049 os << " OStream : " << m.fDefaultOStream[i]
00050 << " Format : " << hexfmt((int)m.fDefaultFormat[i]) << "\n";
00051 }
00052
00053 os << " Active Streams:\n";
00054 i = 0;
00055 map<std::string,MsgStream*>::const_iterator mend(m.fMsgStreamTable.end());
00056 for (map<std::string,MsgStream*>::const_iterator
00057 itr = m.fMsgStreamTable.begin();
00058 itr != mend;
00059 ++itr) {
00060 os << "<" << itr->first << ">";
00061 if (++i%10 == 0) os << "\n";
00062 }
00063 os << "\n";
00064
00065
00066 os << " Concatenated Streams:\n";
00067 vector<MsgCatStream>::const_iterator vend(m.fMsgCatList.end());
00068 for (vector<MsgCatStream>::const_iterator
00069 itrCatStream(m.fMsgCatList.begin());
00070 itrCatStream != vend;
00071 ++itrCatStream) {
00072 os << " " << (*itrCatStream);
00073 }
00074 os << "************************************"
00075 << "************************************\n";
00076 return os;
00077 }
|
|
|
Definition at line 96 of file MsgService.h. Referenced by MsgService(). |
|
|
Definition at line 97 of file MsgService.h. Referenced by MsgService(). |
|
|
Definition at line 91 of file MsgService.h. Referenced by CreateStream(), MsgService(), operator<<(), and SetDefaultFormat(). |
|
|
Definition at line 89 of file MsgService.h. Referenced by CreateStream(), Instance(), MsgService(), and operator<<(). |
|
|
Definition at line 90 of file MsgService.h. Referenced by CreateStream(), MsgService(), and operator<<(). |
|
|
Definition at line 25 of file MsgService.cxx. Referenced by Instance(). |
|
|
Definition at line 93 of file MsgService.h. Referenced by AddCatStream(), operator<<(), and ~MsgService(). |
|
|
Definition at line 92 of file MsgService.h. Referenced by CreateStream(), Instance(), operator<<(), PrintStatistics(), SetGlobalLevel(), and ~MsgService(). |
|
|
Definition at line 27 of file MsgService.cxx. Referenced by MsgService(), and SetGlobalLevel(). |
1.3.9.1