]> SALOME platform Git repositories - tools/libbatch.git/blobdiff - src/Core/BatchManager.cxx
Salome HOME
Add very simple log system
[tools/libbatch.git] / src / Core / BatchManager.cxx
index c369f56c3965e81b8e9d7e2ef3766c09ed14a463..7ee7a56f2cc7c0bfeb093c8775a35a32ea2b2723 100644 (file)
@@ -40,6 +40,7 @@
 #include "BatchManager.hxx"
 #include "Utils.hxx"
 #include "NotYetImplementedException.hxx"
+#include "Log.hxx"
 
 using namespace std;
 
@@ -148,9 +149,8 @@ namespace Batch {
     bool timeoutReached = (testTimeout && time >= timeout);
     JobInfo jinfo = jobid.queryJob();
     string state = jinfo.getParametre()[STATE].str();
-    cout << "State is \"" << state << "\"";
     while (!timeoutReached && state != FINISHED && state != FAILED) {
-      cout << ", sleeping " << sleeptime << "s..." << endl;
+      LOG("State is \"" << state << "\"" << ", sleeping " << sleeptime << "s...");
       Utils::sleep(sleeptime);
       time += sleeptime;
       timeoutReached = (testTimeout && time >= timeout);
@@ -161,9 +161,8 @@ namespace Batch {
         sleeptime = maxSleepTime;
       jinfo = jobid.queryJob();
       state = jinfo.getParametre()[STATE].str();
-      cout << "State is \"" << state << "\"";
     }
-    cout << endl;
+    LOG("State is \"" << state << "\"");
     return state;
   }
 
@@ -208,7 +207,7 @@ namespace Batch {
 
         string subCommand = string("chmod u+x ") + remoteExec;
         string command = _protocol.getExecCommand(subCommand, _hostname, _username);
-        cerr << command.c_str() << endl;
+        LOG(command);
         status = system(command.c_str());
         if (status) {
           std::ostringstream oss;
@@ -248,13 +247,8 @@ namespace Batch {
 
     // Create local result directory
     int status = CommunicationProtocol::getInstance(SH).makeDirectory(directory, "", "");
-    if (status) {
-      string mess("Directory creation failed. Status is :");
-      ostringstream status_str;
-      status_str << status;
-      mess += status_str.str();
-      cerr << mess << endl;
-    }
+    if (status)
+      LOG("Directory creation failed. Status is: " << status);
 
     for(Vit=V.begin(); Vit!=V.end(); Vit++) {
       CoupleType cpt  = *static_cast< CoupleType * >(*Vit);
@@ -269,28 +263,15 @@ namespace Batch {
       }
       status = _protocol.copyFile(remotePath, _hostname, _username,
                                   localPath, "", "");
-      if (status) {
-        // Try to get what we can (logs files)
-        // throw BatchException("Error of connection on remote host");
-        std::string mess("Copy command failed ! status is :");
-        ostringstream status_str;
-        status_str << status;
-        mess += status_str.str();
-        cerr << mess << endl;
-      }
+      if (status)
+        LOG("Copy command failed. Status is: " << status);
     }
 
     // Copy logs
     status = _protocol.copyFile(string(params[WORKDIR]) + string("/logs"), _hostname, _username,
                                 directory, "", "");
-    if (status) {
-      std::string mess("Copy logs directory failed ! status is :");
-      ostringstream status_str;
-      status_str << status;
-      mess += status_str.str();
-      cerr << mess << endl;
-    }
-
+    if (status)
+      LOG("Copy logs directory failed. Status is: " << status);
   }
 
   bool BatchManager::importDumpStateFile( const Job & job, const string directory )
@@ -299,25 +280,14 @@ namespace Batch {
 
     // Create local result directory
     int status = CommunicationProtocol::getInstance(SH).makeDirectory(directory, "", "");
-    if (status) {
-      string mess("Directory creation failed. Status is :");
-      ostringstream status_str;
-      status_str << status;
-      mess += status_str.str();
-      cerr << mess << endl;
-    }
+    if (status)
+      LOG("Directory creation failed. Status is: " << status);
 
     bool ret = true;
     status = _protocol.copyFile(string(params[WORKDIR]) + string("/dumpState*.xml"), _hostname, _username,
                                 directory, "", "");
     if (status) {
-      // Try to get what we can (logs files)
-      // throw BatchException("Error of connection on remote host");
-      std::string mess("Copy command failed ! status is :");
-      ostringstream status_str;
-      status_str << status;
-      mess += status_str.str();
-      cerr << mess << endl;
+      LOG("Copy command failed. Status is: " << status);
       ret = false;
     }
     return ret;