Skip to content

Commit

Permalink
#27910 include in 23.10.24
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Apr 3, 2024
1 parent dc46559 commit 8347d10
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion dotCMS/hotfix_tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ This maintenance release includes the following code fixes:
79. https://github.com/dotCMS/core/issues/26004 : Image field doesn't export as a header in CSV #26004
80. https://github.com/dotCMS/core/issues/23195 : Site Browser: Slow loading folder with many items #23195
81. https://github.com/dotCMS/core/issues/27894 : Security: Critical Vulnerability in Postgres JDBC Driver #27894
82. https://github.com/dotCMS/core/issues/27909 : Invalid role check when accessing resource #27909
82. https://github.com/dotCMS/core/issues/27909 : Invalid role check when accessing resource #27909
83. https://github.com/dotCMS/core/issues/27910 : Log too verbose in certain situations #27910
23 changes: 20 additions & 3 deletions dotCMS/src/main/java/com/dotmarketing/util/RuntimeUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dotmarketing.util;

import com.liferay.util.StringPool;
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 @@ -93,7 +110,7 @@ protected static TerminalOutput runProcessAndGetOutput(final boolean returnError
if (process == null) {
final String errorMsg = String.format("Cannot run process for provided command [ %s ]: %s", String.join(
" ", commands), terminalOutput.output());
Logger.warn(RuntimeUtils.class, errorMsg);
logInfo(errorMsg);
terminalOutput.output(UtilMethods.isSet(terminalOutput.output()) ? terminalOutput.output() : errorMsg);
return terminalOutput;
}
Expand All @@ -117,7 +134,7 @@ protected static TerminalOutput runProcessAndGetOutput(final boolean returnError
}
return terminalOutput;
} catch (final Exception e) {
Logger.error(RuntimeUtils.class, String.format("Error running commands [ %s ]: %s", String.join(" ",
logError(String.format("Error running commands [ %s ]: %s", String.join(" ",
commands), e.getMessage()), e);
return terminalOutput;
} finally {
Expand All @@ -132,7 +149,7 @@ protected static TerminalOutput runProcessAndGetOutput(final boolean returnError
* @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

0 comments on commit 8347d10

Please sign in to comment.