Salome HOME
PR: Garbage text in local trace or crash, in optimized mode : KERNEL 5125
authorprascle <prascle>
Sat, 7 Feb 2004 16:09:12 +0000 (16:09 +0000)
committerprascle <prascle>
Sat, 7 Feb 2004 16:09:12 +0000 (16:09 +0000)
src/SALOMELocalTrace/SALOME_Log.cxx
src/SALOMELocalTrace/SALOME_Log.hxx
src/SALOMELogger/SALOME_LoggerClient.cxx
src/Utils/utilities.h

index 476d987f41b53f4762436464a19bf25a0a619351..ef4f85dedfba33a7b4297b2e55561c119311fd80 100644 (file)
@@ -33,7 +33,12 @@ using namespace std;
 
 #include "SALOME_Log.hxx"
 
-SALOME_Log::SALOME_Log()
+SALOME_Log* SALOME_Log::_singleton = 0;
+
+// log line size: if too short, log line is truncated, without crash...
+char SALOME_LogStr[1024]; 
+
+SALOME_Log::SALOME_Log(): ostrstream(SALOME_LogStr,sizeof(SALOME_LogStr))
 {
 }
 
@@ -41,17 +46,16 @@ SALOME_Log::~SALOME_Log()
 {
 }
 
-SALOME_Log& SALOME_Log::Instance()
+SALOME_Log* SALOME_Log::Instance()
 {
-  static SALOME_Log instance;
-  return instance;
+  if (_singleton == 0) _singleton = new SALOME_Log();
+  return _singleton;
 }
 
 void SALOME_Log::putMessage(std::ostream& msg)
 {
   cout << std::flush;
   cerr <<str() << std::flush;
-  rdbuf()->freeze(false);
-  seekp(0);
 }
 
+
index 043d1e1c2e1efd0eba52977be1101e237336e074..af4f565dadb4fc384da43e10a2b0946834f65609 100644 (file)
@@ -69,17 +69,17 @@ using namespace std;
 
 class SALOME_Log : public ostrstream
 {
-public:
-  virtual ~SALOME_Log();
-  static Standard_EXPORT SALOME_Log& Instance();
-  Standard_EXPORT void putMessage(std::ostream& msg);
-
+private:
+  static SALOME_Log* _singleton;
 protected:
   //disable creation of instances: force use static SALOME_Log& Instance()
   SALOME_Log();
+public:
+  virtual ~SALOME_Log();
+  static Standard_EXPORT SALOME_Log* Instance();
+  Standard_EXPORT void putMessage(std::ostream& msg);
 };
 
-
 #define SLog SALOME_Log::Instance()
 
 #endif
index 70f7650382c31f9e1d25fe8d89fd3bf8c9cb939d..6abf46da948dd09b4ff0f860736df0e1ea201ea2 100644 (file)
@@ -36,15 +36,14 @@ using namespace std;
 #include <SALOMEconfig.h>
 #include CORBA_CLIENT_HEADER(Logger)
 
-// class SALOME_LoggerClient : public SALOME_Log
-// {
-// protected:
-//   SALOME_Logger::Logger_var m_pInterfaceLogger; // object reference on Logger server
-// };
-
 SALOME_Logger::Logger_ptr m_pInterfaceLogger; // object reference on Logger server
 
-SALOME_Log::SALOME_Log()
+SALOME_Log* SALOME_Log::_singleton = 0;
+
+// log line size: if too short, log line is truncated, without crash...
+char SALOME_LogStr[1024]; 
+
+SALOME_Log::SALOME_Log(): ostrstream(SALOME_LogStr,sizeof(SALOME_LogStr))
 {
   cout << "SALOME_LoggerClient: constructor" << endl;
   //get reference on object reference from NS
@@ -131,10 +130,10 @@ SALOME_Log::~SALOME_Log()
 {
 }
 
-SALOME_Log& SALOME_Log::Instance()
+SALOME_Log* SALOME_Log::Instance()
 {
-  static SALOME_Log instance;
-  return instance;
+  if (_singleton == 0) _singleton = new SALOME_Log();
+  return _singleton;
 }
 
 void SALOME_Log::putMessage(std::ostream& msg)
@@ -143,8 +142,8 @@ void SALOME_Log::putMessage(std::ostream& msg)
 
   char* adt = str();
   CORBA::String_var LogMsg = CORBA::string_dup(adt);
-  rdbuf()->freeze(false);
-  seekp(0);
+//   rdbuf()->freeze(false);
+//   seekp(0);
 
   if (CORBA::is_nil(m_pInterfaceLogger))
     cout << LogMsg << std::flush;
index 015e84e58f0fd9263c47337d1e5ebad366078980..f396321e87bcb363775ace52c41f8b1c5626733f 100644 (file)
@@ -37,8 +37,8 @@
 
 /* ---  INFOS is always defined (without _DEBUG_): to be used for warnings, with release version --- */
 
-#define INFOS(msg)    {SLog.putMessage(SLog<<__FILE__<<" ["<<__LINE__<<"] : "<<msg<<endl);}
-#define PYSCRIPT(msg) {SLog.putMessage(SLog<<"---PYSCRIPT--- "<<msg<<endl);}
+#define INFOS(msg)    {SLog->putMessage(*SLog<<__FILE__<<" ["<<__LINE__<<"] : "<<msg<<endl);}
+#define PYSCRIPT(msg) {SLog->putMessage(*SLog<<"---PYSCRIPT--- "<<msg<<endl);}
 
 /* --- To print date and time of compilation of current source --- */
 
@@ -59,8 +59,8 @@
 #endif
 
 #define INFOS_COMPILATION { \
-                          SLog.putMessage(\
-                                          SLog<<__FILE__<<" ["<< __LINE__<<"] : "\
+                          SLog->putMessage(\
+                                          *SLog<<__FILE__<<" ["<< __LINE__<<"] : "\
                                           << "COMPILED with " << COMPILER \
                                           << ", " << __DATE__ \
                                           << " at " << __TIME__ <<endl); }
 
 /* --- the following MACROS are useful at debug time --- */
 
-#define MYTRACE SLog << "- Trace " << __FILE__ << " [" << __LINE__ << "] : " 
+#define MYTRACE *SLog << "- Trace " << __FILE__ << " [" << __LINE__ << "] : " 
 
-#define MESSAGE(msg) {SLog.putMessage( MYTRACE <<msg<<endl<<ends); }
-#define SCRUTE(var)  {SLog.putMessage( MYTRACE << #var << "=" << var <<endl<<ends); }
+#define MESSAGE(msg) {SLog->putMessage( MYTRACE <<msg<<endl<<ends); }
+#define SCRUTE(var)  {SLog->putMessage( MYTRACE << #var << "=" << var <<endl<<ends); }
 
-#define REPERE SLog << "   --------------" << endl 
+#define REPERE *SLog << "   --------------" << endl 
 #define BEGIN_OF(msg) {REPERE;MYTRACE<<"Begin of: "     <<msg<<endl;REPERE;} 
 #define END_OF(msg)   {REPERE;MYTRACE<<"Normal end of: "<<msg<<endl;REPERE;}