From 5a486e4cdbdf21a8dfe7adfef37a7c1db3fa049f Mon Sep 17 00:00:00 2001 From: erickgonzalez Date: Fri, 5 Apr 2024 11:32:47 -0600 Subject: [PATCH] #27910 include in 22.03.15 --- .../com/dotmarketing/util/RuntimeUtils.java | 24 +++++++++++++++---- hotfix_tracking.md | 3 ++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/dotCMS/src/main/java/com/dotmarketing/util/RuntimeUtils.java b/dotCMS/src/main/java/com/dotmarketing/util/RuntimeUtils.java index dd1efd924712..8163f936dc9c 100644 --- a/dotCMS/src/main/java/com/dotmarketing/util/RuntimeUtils.java +++ b/dotCMS/src/main/java/com/dotmarketing/util/RuntimeUtils.java @@ -1,6 +1,7 @@ package com.dotmarketing.util; import com.dotmarketing.exception.DotRuntimeException; +import io.vavr.Lazy; import io.vavr.control.Try; import org.apache.commons.io.IOUtils; @@ -26,6 +27,22 @@ public class RuntimeUtils { public static final String ARM64_ARCH = "aarch64"; public static final String X86_64_ARCH = "x86_64"; + private static final Lazy ENABLE_LOGGING = Lazy.of(() -> { + return Try.of(()->Boolean.parseBoolean(System.getenv("DOT_RUNTIME_ENABLE_LOGGING"))).getOrElse(false); + }); + + + private static void logInfo(String message) { + if (ENABLE_LOGGING.get()) { + Logger.info(RuntimeUtils.class, message); + } + } + private static void logError(String message, Exception e) { + if (ENABLE_LOGGING.get()) { + Logger.error(RuntimeUtils.class, message, e); + } + } + /** * Evaluates if instance is running inside Docker. * @@ -56,8 +73,7 @@ public static InputStream getRunProcessStream(final String... commands) throws I public static Optional runProcessAndGetOutput(final String... commands) { final Process process = Try.of(() -> runProcess(commands)).getOrNull(); if (process == null) { - Logger.warn( - RuntimeUtils.class, + logInfo( String.format("Cannot run process for provided command %s", String.join(" ", commands))); return Optional.empty(); } @@ -74,7 +90,7 @@ public static Optional runProcessAndGetOutput(final String... commands) return Optional.ofNullable(UtilMethods.isSet(input) ? input.replace(System.lineSeparator(), "") : null); } catch (Exception e) { - Logger.error(RuntimeUtils.class, String.format("Error running commands %s", String.join(" ", commands)), e); + logError(String.format("Error running commands %s", String.join(" ", commands)), e); return Optional.empty(); } finally { process.destroy(); @@ -88,7 +104,7 @@ public static Optional runProcessAndGetOutput(final String... commands) * @return process builder */ private static ProcessBuilder buildProcess(String[] commands) { - Logger.info(RuntimeUtils.class, String.format("Executing commands %s", String.join(" ", commands))); + logInfo(String.format("Executing commands %s", String.join(" ", commands))); return new ProcessBuilder(commands).redirectErrorStream(true); } diff --git a/hotfix_tracking.md b/hotfix_tracking.md index 5fd214376016..caf3fe33ca80 100644 --- a/hotfix_tracking.md +++ b/hotfix_tracking.md @@ -243,4 +243,5 @@ This maintenance release includes the following code fixes: **Release-22.03.15** -201. https://github.com/dotCMS/core/issues/27894 : Security: Critical Vulnerability in Postgres JDBC Driver #27894 \ No newline at end of file +201. https://github.com/dotCMS/core/issues/27894 : Security: Critical Vulnerability in Postgres JDBC Driver #27894 +202. https://github.com/dotCMS/core/issues/27910 : Log too verbose in certain situations #27910 \ No newline at end of file