#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))
{
}
{
}
-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);
}
+
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
#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
{
}
-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)
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;
/* --- 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 --- */
#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;}