Salome HOME
[EDF29852] : Mecanism of fault tolerant in SALOME_Container to resist against emitted...
[modules/kernel.git] / src / Basics / libSALOMELog.cxx
index a662bfef4059ee920e9d21091a7f99e68bca148a..ece092484d89653823d2016f4036de5b63023789 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #include <iostream>
 #include <stdexcept>
 
+#include <chrono>
+#include <iomanip>
+#include <ctime>
+
 enum class VerbosityMode { undefined, nolog, withlog };
 
 static VerbosityMode isActivated = VerbosityMode::undefined;
@@ -156,6 +160,11 @@ namespace SALOME
     verbosityLevel = FromStrToVerbosityLevel(level);
   }
 
+  std::vector<std::string> GetAllVerbosityLevelPossibilitiesStr()
+  {
+    return {ERROR_LEVEL_VALUE_STR,WARNING_LEVEL_VALUE_STR,INFO_LEVEL_VALUE_STR,DEBUG_LEVEL_VALUE_STR};
+  }
+
   std::string VerbosityLevelStr()
   {
     return FromVerbosityLevelToStr( VerbosityLevel() );
@@ -180,4 +189,16 @@ namespace SALOME
   {
     return VerbosityLevel() >= VerbosityLevelType::error_level;
   }
+
+  void 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 << " - ";
+  }
 }