From 6aa97cca00b0e37a6b449993eea7cf0e474b57bf Mon Sep 17 00:00:00 2001 From: krasinski <8573352+krasinski@users.noreply.github.com> Date: Fri, 25 Oct 2024 00:32:05 +0200 Subject: [PATCH] GH-16361 allow longer pids by adding sys.ai.h2o.log.max.pid.length [nocheck] (#16390) * GH-16361 allow longer pids by adding sys.ai.h2o.log.max.pid.length * add comment about sys.ai.h2o.log.max.pid.length --- h2o-core/src/main/java/water/util/Log.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/h2o-core/src/main/java/water/util/Log.java b/h2o-core/src/main/java/water/util/Log.java index dc1658f2ec8f..72f8ebf354ba 100644 --- a/h2o-core/src/main/java/water/util/Log.java +++ b/h2o-core/src/main/java/water/util/Log.java @@ -29,8 +29,8 @@ abstract public class Log { public static final byte INFO = 3; public static final byte DEBUG= 4; public static final byte TRACE= 5; - public static final String[] LVLS = { "FATAL", "ERRR", "WARN", "INFO", "DEBUG", "TRACE" }; + private static final String PROP_MAX_PID_LENGTH = H2O.OptArgs.SYSTEM_PROP_PREFIX + "log.max.pid.length"; private static int _level = INFO; private static boolean _quiet = false; @@ -262,7 +262,15 @@ public static String getLogFilePath(String level) { private static String getHostPortPid() { String host = H2O.SELF_ADDRESS.getHostAddress(); - return fixedLength(host + ":" + H2O.API_PORT + " ", 22) + fixedLength(H2O.PID + " ", 6); + return fixedLength(host + ":" + H2O.API_PORT + " ", 22) + fixedLength(H2O.PID + " ", maximumPidLength() + 2); + } + + // set sys.ai.h2o.log.max.pid.length to avoid h2o-3 trimming PID in the logs + private static int maximumPidLength() { + String maxPidPropertyValue = System.getProperty(PROP_MAX_PID_LENGTH); + return maxPidPropertyValue != null + ? Integer.parseInt(maxPidPropertyValue) + : 4; } private static synchronized Logger createLog4j() {