diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2021-03-24 15:53:39 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2021-04-09 08:36:55 +0200 |
commit | da40ceb30d1397f17ad1e414cb27820f952f3f9f (patch) | |
tree | 6c545d3d9610d84bafe102c8f5b6ac85b9469027 | |
parent | 45039e31770e8c5d9438901033c9ada3a57ad1a9 (diff) |
Log "-" for missing log fields in sshd_log
In order to simplify parsing sshd_log files emit a "-" placeholder if a
field is missing in a log record except for LOGIN and LOGOUT which only
log basic fields.
This is a preparation to allow appending new log fields in future Gerrit
versions without disrupting existing tools parsing the sshd_log.
Change-Id: I90adc7618864f702b42029ab596c6014bd4c6cfe
-rw-r--r-- | java/com/google/gerrit/sshd/SshLogLayout.java | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/java/com/google/gerrit/sshd/SshLogLayout.java b/java/com/google/gerrit/sshd/SshLogLayout.java index 1dda0686b8..0779cbe088 100644 --- a/java/com/google/gerrit/sshd/SshLogLayout.java +++ b/java/com/google/gerrit/sshd/SshLogLayout.java @@ -56,11 +56,14 @@ public final class SshLogLayout extends Layout { buf.append(' '); buf.append(event.getMessage()); - opt(P_WAIT, buf, event); - opt(P_EXEC, buf, event); - opt(P_MESSAGE, buf, event); - opt(P_STATUS, buf, event); - opt(P_AGENT, buf, event); + String msg = (String) event.getMessage(); + if (!(msg.startsWith("LOGIN") || msg.equals("LOGOUT"))) { + req(P_WAIT, buf, event); + req(P_EXEC, buf, event); + req(P_MESSAGE, buf, event); + req(P_STATUS, buf, event); + req(P_AGENT, buf, event); + } buf.append('\n'); return buf.toString(); @@ -81,14 +84,6 @@ public final class SshLogLayout extends Layout { } } - private void opt(String key, StringBuffer buf, LoggingEvent event) { - Object val = event.getMDC(key); - if (val != null) { - buf.append(' '); - buf.append(val); - } - } - @Override public boolean ignoresThrowable() { return true; |