diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2019-03-26 17:20:55 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2019-03-26 18:30:27 +0100 |
commit | e73dcf4a2fc8e819824a8a0035c220f2f4dd4e47 (patch) | |
tree | 2c65e586ce69c65b19c21076273361ff44898e0b /vespalog/src/main/java | |
parent | d7649dc2fa83ae8d3ffb73a7324c4637d95b0f1d (diff) |
Expose threadId and processId from LogMessage
Diffstat (limited to 'vespalog/src/main/java')
-rw-r--r-- | vespalog/src/main/java/com/yahoo/log/LogMessage.java | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/vespalog/src/main/java/com/yahoo/log/LogMessage.java b/vespalog/src/main/java/com/yahoo/log/LogMessage.java index 1e2b9dfdab0..3a675d843bd 100644 --- a/vespalog/src/main/java/com/yahoo/log/LogMessage.java +++ b/vespalog/src/main/java/com/yahoo/log/LogMessage.java @@ -1,14 +1,15 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.log; +import com.yahoo.log.event.Event; +import com.yahoo.log.event.MalformedEventException; + +import java.util.OptionalLong; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.yahoo.log.event.Event; -import com.yahoo.log.event.MalformedEventException; - /** * This class implements the common ground log message used by * the logserver. A LogMessage is immutable. Note that we have @@ -34,7 +35,8 @@ public class LogMessage private long time; private String timeStr; private String host; - private String threadProcess; + private long processId; + private long threadId; private String service; private String component; private Level level; @@ -45,14 +47,15 @@ public class LogMessage * Private constructor. Log messages should never be instantiated * directly; only as the result of a static factory method. */ - private LogMessage (String timeStr, Long time, String host, String threadProcess, + private LogMessage (String timeStr, Long time, String host, long processId, long threadId, String service, String component, Level level, String payload) { this.timeStr = timeStr; this.time = time; this.host = host; - this.threadProcess = threadProcess; + this.processId = processId; + this.threadId = threadId; this.service = service; this.component = component; this.level = level; @@ -62,7 +65,13 @@ public class LogMessage public long getTime () {return time;} public long getTimeInSeconds () {return time / 1000;} public String getHost () {return host;} - public String getThreadProcess () {return threadProcess;} + public long getProcessId() {return processId;} + public OptionalLong getThreadId() {return threadId != -1 ? OptionalLong.of(threadId) : OptionalLong.empty();} + /** + * @deprecated Use {@link #getProcessId()} / {@link #getThreadId()} + */ + @Deprecated(since = "7", forRemoval = true) + public String getThreadProcess () {return VespaFormat.formatThreadProcess(processId, threadId);} public String getService () {return service;} public String getComponent () {return component;} public Level getLevel () {return level;} @@ -86,8 +95,9 @@ public class LogMessage Level msgLevel = LogLevel.parse(m.group(6)); Long timestamp = parseTimestamp(m.group(1)); + String threadProcess = m.group(3); - return new LogMessage(m.group(1), timestamp, m.group(2), m.group(3), + return new LogMessage(m.group(1), timestamp, m.group(2), parseProcessId(threadProcess), parseThreadId(threadProcess), m.group(4), m.group(5), msgLevel, m.group(7)); } @@ -100,6 +110,22 @@ public class LogMessage } } + private static long parseProcessId(String threadProcess) { + int slashIndex = threadProcess.indexOf('/'); + if (slashIndex == -1) { + return Long.parseLong(threadProcess); + } + return Long.parseLong(threadProcess.substring(0, slashIndex)); + } + + private static long parseThreadId(String threadProcess) { + int slashIndex = threadProcess.indexOf('/'); + if (slashIndex == -1) { + return -1; + } + return Long.parseLong(threadProcess.substring(slashIndex + 1)); + } + /** * If the LogMessage was an EVENT then this method can * be used to get the Event instance representing the @@ -131,6 +157,7 @@ public class LogMessage * Return valid representation of log message. */ public String toString () { + String threadProcess = VespaFormat.formatThreadProcess(processId, threadId); return new StringBuilder(timeStr.length() + host.length() + threadProcess.length() |