Salome HOME
[bos #29467] [EDF] (2022-T1) Logging of SALOME usage: specific log in SALOME
authorjfa <jfa@opencascade.com>
Thu, 26 May 2022 11:48:51 +0000 (14:48 +0300)
committerPascal Obry <pascal.obry@edf.fr>
Tue, 5 Sep 2023 09:36:26 +0000 (11:36 +0200)
src/LightApp/LightApp_Application.cxx
src/LightApp/LightApp_Application.h

index 19639c2812cea9d2732149a0cecf41434ad2d981..e6781704fc8a26e37023de6ca5fd0a6ba2685e3b 100644 (file)
 #include <QMimeData>
 #include <QShortcut>
 #include <QRegExp>
+#include <QMutex>
+#include <QMutexLocker>
 
 #include <utilities.h>
 
@@ -5773,6 +5775,47 @@ bool LightApp_Application::checkExistingDoc( bool closeExistingDoc )
   return result;
 }
 
+/*!
+  Log GUI action
+*/
+void LightApp_Application::logUserEvent(const QString& eventDescription)
+{
+  static QString _gui_log_file_ = "Not initialized";
+  static QMutex aGUILogMutex;
+  if (_gui_log_file_ == "Not initialized") {
+    std::cout << "!!!***aaajfa***!!! _gui_log_file_ initialization" << std::endl;
+    _gui_log_file_ = "";
+    QStringList args = QApplication::arguments();
+    for (int i = 1; i < args.count(); i++) {
+      QRegExp rxs ("--gui-log-file=(.+)");
+      if (rxs.indexIn( args[i] ) >= 0 && rxs.capturedTexts().count() > 1) {
+        QString file = rxs.capturedTexts()[1];
+        QFileInfo fi ( file );
+        if (!fi.isDir()) {
+          if (fi.dir().exists()) {
+            _gui_log_file_ = fi.absoluteFilePath();
+            if (fi.exists()) {
+              QFile file (_gui_log_file_);
+              file.remove();
+            }
+          }
+        }
+        break;
+      }
+    }
+  }
+  if (_gui_log_file_ != "") {
+    std::cout << "!!!***aaajfa***!!! log User Event: " << eventDescription.toStdString() << std::endl;
+    QMutexLocker aLocker (&aGUILogMutex);
+    QFile file (_gui_log_file_);
+    if (file.open(QFile::Append)) {
+      QTextStream stream( &file );
+      stream << eventDescription << endl;
+      file.close();
+    }
+  }
+}
+
 #ifndef DISABLE_PYCONSOLE
 
 PyConsole_Interp* LightApp_Application::getPyInterp()
index cb2102e1977519d6a6cbee1ba89ae6dd65f777bb..351c1663ce5b8f8e3813d506097f2a30f171e7a8 100644 (file)
@@ -191,6 +191,8 @@ public:
 
   virtual bool                        checkExistingDoc( bool = true );
 
+  static void                         logUserEvent(const QString& eventDescription);
+
 #ifndef DISABLE_PYCONSOLE
   PyConsole_Interp*                   getPyInterp();
 #endif