Skip to content

Commit

Permalink
Add environment variables and system properties to the self-diagnosti…
Browse files Browse the repository at this point in the history
…cs (#2737)
  • Loading branch information
jeanbisutti authored Dec 1, 2022
1 parent 90573b8 commit c75a1c1
Showing 1 changed file with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.lang.management.RuntimeMXBean;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Properties;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -101,22 +102,37 @@ public void init() {
}

if (startupLogger.isDebugEnabled()) {
startupLogger.debug("OS: " + System.getProperty("os.name"));
logJavaInfo();
startupLogger.debug("Netty versions: " + NettyVersions.extract());
startupLogger.debug(
"Input arguments: " + ManagementFactory.getRuntimeMXBean().getInputArguments());
startupLogger.debug("_JAVA_OPTIONS: " + System.getenv("_JAVA_OPTIONS"));
startupLogger.debug("JAVA_TOOL_OPTIONS: " + System.getenv("JAVA_TOOL_OPTIONS"));
}

if (startupLogger.isTraceEnabled()) {
startupLogger.trace("OS: " + System.getProperty("os.name"));
startupLogger.trace("Classpath: " + System.getProperty("java.class.path"));
startupLogger.trace("Netty versions: " + NettyVersions.extract());
startupLogger.trace("Env: " + System.getenv());
startupLogger.trace("System properties: " + findSystemProperties());
}

} catch (Exception e) {
throw new IllegalStateException(e);
}
}

private static void logJavaInfo() {
startupLogger.debug("Classpath: " + System.getProperty("java.class.path"));
startupLogger.debug(
"Input arguments: " + ManagementFactory.getRuntimeMXBean().getInputArguments());
startupLogger.debug("_JAVA_OPTIONS: " + System.getenv("_JAVA_OPTIONS"));
startupLogger.debug("JAVA_TOOL_OPTIONS: " + System.getenv("JAVA_TOOL_OPTIONS"));
private static String findSystemProperties() {
Properties properties = System.getProperties();
StringBuilder propsBuilder = new StringBuilder();
properties.forEach(
(key, value) -> {
boolean firstProperty = propsBuilder.length() == 0;
if (!firstProperty) {
propsBuilder.append(", ");
}
propsBuilder.append("(" + key + "=" + value + ")");
});
return propsBuilder.toString();
}

@Override
Expand Down

0 comments on commit c75a1c1

Please sign in to comment.