diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/logging/CppLogMessageHandler.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/logging/CppLogMessageHandler.java index d295a806cec..01678e7b03e 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/logging/CppLogMessageHandler.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/logging/CppLogMessageHandler.java @@ -50,6 +50,7 @@ public class CppLogMessageHandler implements Closeable { private volatile boolean hasLogStreamEnded; private volatile boolean seenFatalError; private volatile long pid; + private volatile String cppCopyright; /** * @param jobId May be null or empty if the logs are from a process not associated with a job. @@ -132,6 +133,10 @@ public class CppLogMessageHandler implements Closeable { return pid; } + public String getCppCopyright() { + return cppCopyright; + } + /** * Expected to be called very infrequently. */ @@ -185,12 +190,15 @@ public class CppLogMessageHandler implements Closeable { pid = latestPid; pidLatch.countDown(); } + String latestMessage = msg.getMessage(); + if (cppCopyright == null && latestMessage.contains("Copyright")) { + cppCopyright = latestMessage; + } // TODO: Is there a way to preserve the original timestamp when re-logging? if (jobId != null) { - LOGGER.log(level, "[{}] {}/{} {}@{} {}", jobId, msg.getLogger(), latestPid, msg.getFile(), msg.getLine(), - msg.getMessage()); + LOGGER.log(level, "[{}] {}/{} {}@{} {}", jobId, msg.getLogger(), latestPid, msg.getFile(), msg.getLine(), latestMessage); } else { - LOGGER.log(level, "{}/{} {}@{} {}", msg.getLogger(), latestPid, msg.getFile(), msg.getLine(), msg.getMessage()); + LOGGER.log(level, "{}/{} {}@{} {}", msg.getLogger(), latestPid, msg.getFile(), msg.getLine(), latestMessage); } // TODO: Could send the message for indexing instead of or as well as logging it } catch (IOException e) { diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/logging/CppLogMessageHandlerTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/logging/CppLogMessageHandlerTests.java index 1e0c0a633de..29ce19674f1 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/logging/CppLogMessageHandlerTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/logging/CppLogMessageHandlerTests.java @@ -27,8 +27,8 @@ public class CppLogMessageHandlerTests extends ESTestCase { + "/var/folders/k5/5sqcdlps5sg3cvlp783gcz740000h0/T/controller_log_784\",\"class\":\"ml\"," + "\"method\":\"core::CLogger::reconfigureLogToNamedPipe\",\"file\":\"CLogger.cc\",\"line\":333}\n" + "{\"logger\":\"controller\",\"timestamp\":1478261151445,\"level\":\"INFO\",\"pid\":10211,\"thread\":\"0x7fff7d2a8000\"," - + "\"message\":\"controller (64 bit): Version based on 6.5.0 (Build DEVELOPMENT BUILD by dave) " - + "Copyright (c) 2016 Elasticsearch BV\",\"method\":\"main\",\"file\":\"Main.cc\",\"line\":123}\n" + + "\"message\":\"controller (64 bit): Version based on 6.0.0-alpha1 (Build b0d6ef8819418c) " + + "Copyright (c) 2017 Elasticsearch BV\",\"method\":\"main\",\"file\":\"Main.cc\",\"line\":123}\n" + "{\"logger\":\"controller\",\"timestamp\":1478261169065,\"level\":\"ERROR\",\"pid\":10211,\"thread\":\"0x7fff7d2a8000\"," + "\"message\":\"Did not understand verb 'a'\",\"class\":\"ml\"," + "\"method\":\"controller::CCommandProcessor::handleCommand\",\"file\":\"CCommandProcessor.cc\",\"line\":100}\n" @@ -43,6 +43,8 @@ public class CppLogMessageHandlerTests extends ESTestCase { assertTrue(handler.hasLogStreamEnded()); assertEquals(10211L, handler.getPid(Duration.ofMillis(1))); + assertEquals("controller (64 bit): Version based on 6.0.0-alpha1 (Build b0d6ef8819418c) " + + "Copyright (c) 2017 Elasticsearch BV", handler.getCppCopyright()); assertEquals("Did not understand verb 'a'\n", handler.getErrors()); assertFalse(handler.seenFatalError()); }