Salome HOME
[EDF29150] : Add some dynamic traces + assign a more explicite name in perflog
[modules/yacs.git] / src / bases / YacsTrace.cxx
index d6fc69ad17feb1d79926438020a2b16f731f0d8e..c734677785529baf8898dd99f279156f4052ef7b 100644 (file)
 #include "YacsTrace.hxx"
 #include <cstdlib>
 
+#include <chrono>
+#include <iomanip>
+#include <ctime>
+
 #ifdef WIN32
 #include <process.h>
 #define getpid _getpid
 #include <unistd.h>
 #endif
 
-namespace YACS{
-    int traceLevel=0;
+namespace YACS {
+  int traceLevel = 0;
+}
+
+void YACS::AppendTimeClock(std::ostream& os)
+{
+  auto now = std::chrono::system_clock::now();
+  auto duration = now.time_since_epoch();
+  auto timestamp = std::chrono::system_clock::to_time_t(now);
+  std::tm *local_time = std::localtime(&timestamp);
+  auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
+  os  << std::setfill('0') << std::setw(2) << local_time->tm_hour << ":"
+      << std::setw(2) << local_time->tm_min << ":"
+      << std::setw(2) << local_time->tm_sec << "." << std::setw(3) << millis % 1000 << " - ";
 }
 
 void AttachDebugger()