This is an automated email from the ASF dual-hosted git repository.

jasonhuynh pushed a commit to branch support/1.13
in repository https://gitbox.apache.org/repos/asf/geode.git

commit d78f66c10eda48748ba6069050875da1222ae22b
Author: Jason Huynh <[email protected]>
AuthorDate: Tue Jun 2 10:17:05 2020 -0700

    GEODE-8203: Provide ability to prevent disabling geode console appender 
(#5183)
    
    (cherry picked from commit 4f559fc4d35ed4950faa083689e35a35c75eaa2f)
---
 .../geode/logging/internal/LoggingSession.java     | 16 +++++++++++++++-
 .../geode/logging/internal/LoggingSessionTest.java | 22 ++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git 
a/geode-core/src/main/java/org/apache/geode/logging/internal/LoggingSession.java
 
b/geode-core/src/main/java/org/apache/geode/logging/internal/LoggingSession.java
index ea31885..3f56dc8 100644
--- 
a/geode-core/src/main/java/org/apache/geode/logging/internal/LoggingSession.java
+++ 
b/geode-core/src/main/java/org/apache/geode/logging/internal/LoggingSession.java
@@ -18,6 +18,7 @@ import static 
org.apache.geode.logging.internal.Configuration.STARTUP_CONFIGURAT
 import static 
org.apache.geode.logging.internal.InternalSessionContext.State.CREATED;
 import static 
org.apache.geode.logging.internal.InternalSessionContext.State.STARTED;
 import static 
org.apache.geode.logging.internal.InternalSessionContext.State.STOPPED;
+import static org.apache.geode.util.internal.GeodeGlossary.GEMFIRE_PREFIX;
 
 import java.util.Optional;
 
@@ -34,6 +35,9 @@ import org.apache.geode.logging.internal.spi.LogFile;
  */
 public class LoggingSession implements InternalSessionContext {
 
+  static final boolean STANDARD_OUTPUT_ALWAYS_ON =
+      Boolean.valueOf(System.getProperty(GEMFIRE_PREFIX + 
"StandardOutputAlwaysOn", "false"));
+
   private static final Logger logger = LogService.getLogger();
 
   private final Configuration configuration;
@@ -41,6 +45,7 @@ public class LoggingSession implements InternalSessionContext 
{
 
   private volatile boolean logBanner;
   private volatile boolean logConfiguration;
+  private volatile boolean standardOutputAlwaysOn;
 
   private State state = STOPPED;
 
@@ -66,12 +71,19 @@ public class LoggingSession implements 
InternalSessionContext {
 
   public synchronized void createSession(final LogConfigSupplier 
logConfigSupplier,
       final boolean logBanner, final boolean logConfiguration) {
+    createSession(logConfigSupplier, logBanner, logConfiguration, 
STANDARD_OUTPUT_ALWAYS_ON);
+  }
+
+  public synchronized void createSession(final LogConfigSupplier 
logConfigSupplier,
+      final boolean logBanner, final boolean logConfiguration,
+      final boolean standardOutputAlwaysOn) {
     configuration.initialize(logConfigSupplier);
     state = state.changeTo(CREATED);
     loggingSessionNotifier.createSession(this);
 
     this.logBanner = logBanner;
     this.logConfiguration = logConfiguration;
+    this.standardOutputAlwaysOn = standardOutputAlwaysOn;
   }
 
   /**
@@ -80,7 +92,9 @@ public class LoggingSession implements InternalSessionContext 
{
   public synchronized void startSession() {
     state = state.changeTo(STARTED);
     loggingSessionNotifier.startSession();
-    configuration.disableLoggingToStandardOutputIfLoggingToFile();
+    if (!standardOutputAlwaysOn) {
+      configuration.disableLoggingToStandardOutputIfLoggingToFile();
+    }
 
     if (logBanner) {
       logger.info(new 
Banner(configuration.getConfigurationInfo()).getString());
diff --git 
a/geode-core/src/test/java/org/apache/geode/logging/internal/LoggingSessionTest.java
 
b/geode-core/src/test/java/org/apache/geode/logging/internal/LoggingSessionTest.java
index ef16779..81f7087 100644
--- 
a/geode-core/src/test/java/org/apache/geode/logging/internal/LoggingSessionTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/logging/internal/LoggingSessionTest.java
@@ -30,6 +30,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.mockito.InOrder;
+import org.mockito.Mockito;
 
 import org.apache.geode.logging.internal.spi.LogConfig;
 import org.apache.geode.logging.internal.spi.LogConfigSupplier;
@@ -94,6 +95,27 @@ public class LoggingSessionTest {
   }
 
   @Test
+  public void 
createSessionInvokesDisableLoggingToStandardOutputIfLoggingToFileByDefault() {
+    loggingSession.createSession(logConfigSupplier);
+    loggingSession.startSession();
+
+    verify(configuration).initialize(eq(logConfigSupplier));
+    verify(configuration).configChanged();
+    verify(configuration).disableLoggingToStandardOutputIfLoggingToFile();
+  }
+
+  @Test
+  public void 
createSessionDoesNotDisableLoggingToStandardOutputIfSystemPropertySet() {
+    loggingSession.createSession(logConfigSupplier, true, true, true);
+    loggingSession.startSession();
+
+    verify(configuration).initialize(eq(logConfigSupplier));
+    verify(configuration).configChanged();
+    verify(configuration, 
Mockito.times(0)).disableLoggingToStandardOutputIfLoggingToFile();
+  }
+
+
+  @Test
   public void createSessionPublishesConfigBeforeCreatingLoggingSession() {
     loggingSession.createSession(logConfigSupplier);
 

Reply via email to