StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StDbWrappedMessenger.cc
1 /***************************************************************************
2  *
3  * $Id: StDbWrappedMessenger.cc,v 1.10 2011/01/07 17:12:28 dmitry Exp $
4  *
5  * Author: R. Jeff Porter
6  ***************************************************************************
7  *
8  * Description: Implements the abstract StDbMessService class with
9  * a pointer to the StUtilities singleton StMessageManager
10  * to make use of the general STAR offline messaging utility
11  *
12  ***************************************************************************
13  *
14  * $Log: StDbWrappedMessenger.cc,v $
15  * Revision 1.10 2011/01/07 17:12:28 dmitry
16  * fixed pseudo-leaks in c-string and xml-string assignments
17  *
18  * Revision 1.9 2009/08/25 17:00:43 fine
19  * fix the compilation issues under SL5_64_bits gcc 4.3.2
20  *
21  * Revision 1.8 2007/08/08 20:51:04 fine
22  * replace the cutom messanger with the standard STAR logger
23  *
24  * Revision 1.7 2006/08/08 14:28:09 deph
25  * fixed delete to delete allocated array
26  *
27  * Revision 1.6 2005/12/08 18:13:27 deph
28  * Made message length dynamic. We were bumping up against the 1024 limit in verbose mode.
29  *
30  * Revision 1.5 2003/09/12 01:48:06 porter
31  * removed all strstream objects in favor of stringstream+string directly
32  *
33  * Revision 1.4 2001/06/05 22:08:34 perev
34  * HP corr
35  *
36  * Revision 1.3 2001/04/23 14:01:58 porter
37  * fixed bug in messages
38  *
39  * Revision 1.2 2001/01/26 14:48:41 porter
40  * fixed tag so verbose output works correctly
41  *
42  * Revision 1.1 2001/01/22 18:40:25 porter
43  * Added a wrapper for StMessage so one can use it in StDbLib
44  *
45  **************************************************************************/
46 
47 #include "StDbWrappedMessenger.hh"
48 #include <string.h>
49 #include <assert.h>
50 #include "StUtilities/StMessageManager.h"
51 
53 
54 StDbWrappedMessenger::StDbWrappedMessenger() {
55  mMessenger=StMessageManager::Instance();
56 };
57 
59 
60 void
61 StDbWrappedMessenger::printMessage(const char* message, StDbMessLevel dbLevel, int lineNumber, const char* className, const char* methodName) {
62 
63 if (dbLevel<mdbLevel) return;
64 
65 // int n = strlen(message)+1000;
66 // char * str = new char[n];
67 
68  std::ostringstream ostr;
69  ostr << className << "::" << methodName << " line=" << lineNumber << " " << message;
70 
71  std::string str = ostr.str();
72 
73 // sprintf(str,"%s::%s line=%d %s",className,methodName,lineNumber,message);
74 
75  char lString[64];
76  switch(dbLevel){
77  case dbMDebug:
78  {
79  strcpy(lString,"I");
80  LOG_DEBUG << str << endm;
81  break;
82  }
83  case dbMWarn:
84  {
85  strcpy(lString,"W");
86  LOG_WARN << str << endm;
87  break;
88  }
89  case dbMConnect:
90  {
91  strcpy(lString,"I");
92  LOG_INFO << str << endm;
93  break;
94  }
95  case dbMErr:
96  {
97  strcpy(lString,"E");
98  LOG_ERROR << str << endm;
99  break;
100  }
101  default:
102  {
103  strcpy(lString," ");
104  LOG_INFO << str << endm;
105  break;
106  }
107  // delete [] str;
108  }
109 
110 // printMessage(message,(const char*)lString,lineNumber,className,methodName);
111 }
112 
114 
115 void
116 StDbWrappedMessenger::printMessage(const char* message, const char* levelString, int lineNumber, const char* className, const char* methodName) {
117 
118  //
119  // limit here of 1024 only hits us for the StDbManager in verbose mode
120  // which isn't available directly in StRoot
121  //
122 
123 // char str[1024];
124  assert(0);
125  int n = strlen(message)+1000;
126  char * str = new char[n];
127 
128  sprintf(str,"%s::%s line=%d %s",className,methodName,lineNumber,message);
129  mMessenger->Message(str,levelString);
130  delete [] str;
131 }
132 
133