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

clebertsuconic pushed a commit to branch new-logging
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/new-logging by this push:
     new 4ee9dd1343 Adding Step to verify if the broker has a log4j.properties 
configuration. if it does not the broker will install one by default
4ee9dd1343 is described below

commit 4ee9dd1343f51b5fdb126f961fe086bd38b88b1e
Author: Clebert Suconic <[email protected]>
AuthorDate: Mon Sep 19 18:35:29 2022 -0400

    Adding Step to verify if the broker has a log4j.properties configuration. 
if it does not the broker will install one by default
    
    This is an idea to deal with bringing older broker configuration.
    
    Perhas we could expand to convert the logging.properties as 
log4j.properties.. if people find that important. (I don't think it's a big 
deal)
---
 .../artemis/cli/commands/ActionAbstract.java       | 23 ++++++++++++++++++++++
 .../org/apache/activemq/cli/test/ArtemisTest.java  | 19 ++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git 
a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/ActionAbstract.java
 
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/ActionAbstract.java
index 54044616fb..fed4f4add0 100644
--- 
a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/ActionAbstract.java
+++ 
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/ActionAbstract.java
@@ -17,12 +17,16 @@
 package org.apache.activemq.artemis.cli.commands;
 
 import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.InetAddress;
 import java.net.URI;
 import java.util.Map;
 
 import io.airlift.airline.Option;
 import org.apache.activemq.artemis.api.core.TransportConfiguration;
+import org.apache.activemq.artemis.cli.CLIException;
 import org.apache.activemq.artemis.core.config.Configuration;
 import org.apache.activemq.artemis.core.config.FileDeploymentManager;
 import org.apache.activemq.artemis.core.config.impl.FileConfiguration;
@@ -87,6 +91,21 @@ public abstract class ActionAbstract implements Action {
       return brokerInstance;
    }
 
+
+   protected void verifyLoggingConfiguration() throws Exception {
+      File brokerInstanceFile = new File(getBrokerInstance());
+      File etc = new File(brokerInstanceFile, "etc");
+      File log4jConfig = new File(etc, Create.ETC_LOG4J2_PROPERTIES);
+
+      if (!log4jConfig.exists()) {
+         try (InputStream inputStream = 
this.getClass().getResourceAsStream("etc/" + Create.ETC_LOG4J2_PROPERTIES);
+              OutputStream outputStream = new FileOutputStream(log4jConfig)) {
+            outputStream.write(inputStream.readAllBytes());
+         }
+         throw new CLIException(Create.ETC_LOG4J2_PROPERTIES + " could not be 
found under " + etc.getAbsolutePath() + ". A new file default file was just 
created. Please retry the execution now after the configuration been placed");
+      }
+   }
+
    public String getBrokerURLInstance(String acceptor) {
       if (getBrokerInstance() != null) {
          try {
@@ -188,6 +207,10 @@ public abstract class ActionAbstract implements Action {
       this.actionContext = context;
       ActionContext.setSystem(context);
 
+      if (getBrokerInstance() != null) {
+         verifyLoggingConfiguration();
+      }
+
       return null;
    }
 
diff --git 
a/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java 
b/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java
index c223619451..8896583e7a 100644
--- a/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java
+++ b/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java
@@ -183,6 +183,25 @@ public class ArtemisTest extends CliTestBase {
       Artemis.main("create", instance1.getAbsolutePath(), "--silent", 
"--no-fsync", "--no-autotune");
    }
 
+   @Test
+   public void testVerifySystemLog() throws Exception {
+      File instance1 = new File(temporaryFolder.getRoot(), "instance1");
+      Artemis.main("create", instance1.getAbsolutePath(), "--silent", 
"--no-fsync", "--no-autotune");
+      File etc = new File(instance1, "etc");
+      File log4jLogging = new File(etc, Create.ETC_LOG4J2_PROPERTIES);
+      Assert.assertTrue(log4jLogging.exists());
+      log4jLogging.delete();
+      Assert.assertFalse(log4jLogging.exists());
+      System.setProperty("artemis.instance", instance1.getAbsolutePath());
+      try {
+         Artemis.internalExecute("run");
+         Assert.fail("expected failure");
+      } catch (CLIException expected) {
+         // I expect the system to not start with an error, however the file 
will be recreated
+      }
+      Assert.assertTrue(log4jLogging.exists());
+   }
+
 
    @Test
    public void testCreateDB() throws Exception {

Reply via email to