Browse Source

Merge pull request #14569 from jakesmith/hpcc-25342-eclcc-logging

HPCC-25342 Capture eclcc logging in containerized mode

Reviewed-By: Gavin Halliday <gavin.halliday@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 4 years ago
parent
commit
eb139de422

+ 1 - 1
dockerfiles/platform-core-debug/Dockerfile

@@ -37,4 +37,4 @@ ENV HPCC_DLLSERVER_PATH=/var/lib/HPCCSystems/queries
 
 USER hpcc
 WORKDIR /var/lib/HPCCSystems
-RUN eclcc -pch && rm eclcc.log
+RUN eclcc -pch

+ 1 - 1
dockerfiles/platform-core/Dockerfile

@@ -82,4 +82,4 @@ ENV PATH="/opt/HPCCSystems/bin:${PATH}"
 ENV HPCC_containerized=1
 ENV HPCC_DLLSERVER_PATH=/var/lib/HPCCSystems/queries
 WORKDIR /var/lib/HPCCSystems
-RUN eclcc -pch && rm eclcc.log
+RUN eclcc -pch

+ 27 - 11
ecl/eclcc/eclcc.cpp

@@ -399,6 +399,7 @@ protected:
     bool optWorkUnit = false;
     bool optNoCompile = false;
     bool optNoLogFile = false;
+    bool optLogToStdOut = false;
     bool optNoStdInc = false;
     bool optNoBundles = false;
     bool optBatchMode = false;
@@ -673,21 +674,33 @@ void EclCC::loadOptions()
     }
     extractOption(stdIncludeLibraryPath, globals, "ECLCC_ECLINCLUDE_PATH", "eclIncludePath", ".", NULL);
 
-    if (!optLogfile.length() && !optBatchMode && !optNoLogFile)
-        extractOption(optLogfile, globals, "ECLCC_LOGFILE", "logfile", "eclcc.log", NULL);
-
-    if ((logVerbose || optLogfile) && !optNoLogFile)
+    if (optLogToStdOut)
+    {
+        Owned<ILogMsgHandler> handler = getHandleLogMsgHandler(stdout);
+        handler->setMessageFields(MSGFIELD_STANDARD);
+        Owned<ILogMsgFilter> filter = getCategoryLogMsgFilter(MSGAUD_all, MSGCLS_all, optLogDetail ? optLogDetail : DefaultDetail, true);
+        queryLogMsgManager()->addMonitor(handler, filter);
+    }
+#ifndef _CONTAINERIZED
+    else
     {
-        if (optLogfile.length())
+        if (!optLogfile.length() && !optBatchMode && !optNoLogFile)
+            extractOption(optLogfile, globals, "ECLCC_LOGFILE", "logfile", "eclcc.log", NULL);
+
+        if ((logVerbose || optLogfile) && !optNoLogFile)
         {
-            StringBuffer lf;
-            openLogFile(lf, optLogfile, optLogDetail, false);
-            if (logVerbose)
-                fprintf(stdout, "Logging to '%s'\n",lf.str());
+            if (optLogfile.length())
+            {
+                StringBuffer lf;
+                openLogFile(lf, optLogfile, optLogDetail, false);
+                if (logVerbose)
+                    fprintf(stdout, "Logging to '%s'\n",lf.str());
+            }
+            if (optMonitorInterval)
+                startPerformanceMonitor(optMonitorInterval*1000, PerfMonStandard, nullptr);
         }
-        if (optMonitorInterval)
-            startPerformanceMonitor(optMonitorInterval*1000, PerfMonStandard, nullptr);
     }
+#endif
 
     if (hooksPath.length())
         installFileHooks(hooksPath.str());
@@ -2708,6 +2721,9 @@ int EclCC::parseCommandLineOptions(int argc, const char* argv[])
         else if (iter.matchFlag(optNoLogFile, "--nologfile"))
         {
         }
+        else if (iter.matchFlag(optLogToStdOut, "--logtostdout"))
+        {
+        }
         else if (iter.matchFlag(optIgnoreSignatures, "--nogpg"))
         {
         }

+ 12 - 0
ecl/eclccserver/eclccserver.cpp

@@ -340,8 +340,16 @@ class EclccCompileThread : implements IPooledThread, implements IErrorReporter,
         eclccCmd.append(" --timings --xml");
         eclccCmd.append(" --nostdinc");
         eclccCmd.append(" --metacache=");
+
+#ifdef _CONTAINERIZED
+        /* stderr is reserved for actual errors, and is consumed by this (parent) process
+         * stdout is unused and will be captured by container logging mechanism */
+        eclccCmd.append(" --logtostdout");
+#else
         VStringBuffer logfile("%s.eclcc.log", workunit->queryWuid());
         eclccCmd.appendf(" --logfile=%s", logfile.str());
+#endif
+
         if (syntaxCheck)
             eclccCmd.appendf(" -syntax");
 
@@ -440,7 +448,9 @@ class EclccCompileThread : implements IPooledThread, implements IErrorReporter,
                 createUNCFilename(realdllfilename.str(), dllurl);
                 unsigned crc = crc_file(realdllfilename.str());
                 Owned<IWUQuery> query = workunit->updateQuery();
+#ifndef _CONTAINERIZED
                 associateLocalFile(query, FileTypeLog, logfile, "Compiler log", 0);
+#endif
                 associateLocalFile(query, FileTypeDll, realdllfilename, "Workunit DLL", crc);
                 queryDllServer().registerDll(realdllname.str(), "Workunit DLL", dllurl.str());
                 workunit->commit();
@@ -448,9 +458,11 @@ class EclccCompileThread : implements IPooledThread, implements IErrorReporter,
             }
             else
             {
+#ifndef _CONTAINERIZED
                 Owned<IWUQuery> query = workunit->updateQuery();
                 associateLocalFile(query, FileTypeLog, logfile, "Compiler log", 0);
                 workunit->commit();
+#endif
                 return false;
             }
         }