Skip to content

Commit

Permalink
#27910 include in 22.03.15
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Apr 5, 2024
1 parent 6fa8cd0 commit 5a486e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
24 changes: 20 additions & 4 deletions 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;

Expand All @@ -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<Boolean> 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.
*
Expand Down Expand Up @@ -56,8 +73,7 @@ public static InputStream getRunProcessStream(final String... commands) throws I
public static Optional<String> 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();
}
Expand All @@ -74,7 +90,7 @@ public static Optional<String> 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();
Expand All @@ -88,7 +104,7 @@ public static Optional<String> 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);
}

Expand Down
3 changes: 2 additions & 1 deletion hotfix_tracking.md
Expand Up @@ -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
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

0 comments on commit 5a486e4

Please sign in to comment.