[ 
https://issues.apache.org/jira/browse/ARTEMIS-4020?focusedWorklogId=815175&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-815175
 ]

ASF GitHub Bot logged work on ARTEMIS-4020:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 10/Oct/22 12:08
            Start Date: 10/Oct/22 12:08
    Worklog Time Spent: 10m 
      Work Description: gemmellr commented on code in PR #4246:
URL: https://github.com/apache/activemq-artemis/pull/4246#discussion_r991209180


##########
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/InitLogging.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.cli.commands.tools;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.lang.invoke.MethodHandles;
+import java.util.Collections;
+
+import io.airlift.airline.Command;
+import io.airlift.airline.Option;
+import org.apache.activemq.artemis.cli.commands.ActionAbstract;
+import org.apache.activemq.artemis.cli.commands.ActionContext;
+import org.apache.activemq.artemis.cli.commands.Create;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Command(name = "init-logging", description = "Initialize a default log4j 
configuration")
+public class InitLogging extends ActionAbstract {
+
+   private static final Logger logger = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+   public static final String OLD_LOG_NAME = "logging.properties";
+
+   @Option(name = "--force", description = "Overwrite configuration at 
destination directory")
+   private boolean force;
+
+   @Override
+   public Object execute(ActionContext context) throws Exception {
+      super.execute(context);
+
+      initLogging(force, new File(getBrokerInstance()));
+
+      return null;
+   }
+
+
+   public static void initLogging(boolean force, File brokerInstance) throws 
Exception {
+      File etc = new File(brokerInstance, "etc");
+      File newLogging = new File(etc, Create.ETC_LOG4J2_PROPERTIES);
+
+      if (!force && newLogging.exists()) {
+         System.err.println("A configuration file " + 
newLogging.getAbsolutePath() + " already exists! Use the option -f if you want 
to re-initialize it");
+         return;
+      }
+
+      Create.write("etc/" + Create.ETC_LOG4J2_PROPERTIES, newLogging, 
Collections.emptyMap(), false, force, "utf-8");
+   }
+
+   public static void verifyOlderLogging(File fileInstance) throws Exception {
+      File etc = new File(fileInstance, "etc");
+      File newLogging = new File(etc, Create.ETC_LOG4J2_PROPERTIES);
+      File oldLogging = new File(etc, OLD_LOG_NAME);
+
+      if (oldLogging.exists() && !newLogging.exists()) {
+         logger.warn("Logging not initialized!");

Review Comment:
   Using logging to warn about logging doesnt necessarily make sense. In 
particular it will probably do nothing if there is no config, as the default is 
Error, and if there is configuration via one of the many other valid routes 
this doesnt consider, it will then log this incorrectly.



##########
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/InitLogging.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.cli.commands.tools;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.lang.invoke.MethodHandles;
+import java.util.Collections;
+
+import io.airlift.airline.Command;
+import io.airlift.airline.Option;
+import org.apache.activemq.artemis.cli.commands.ActionAbstract;
+import org.apache.activemq.artemis.cli.commands.ActionContext;
+import org.apache.activemq.artemis.cli.commands.Create;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Command(name = "init-logging", description = "Initialize a default log4j 
configuration")
+public class InitLogging extends ActionAbstract {
+
+   private static final Logger logger = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+   public static final String OLD_LOG_NAME = "logging.properties";
+
+   @Option(name = "--force", description = "Overwrite configuration at 
destination directory")
+   private boolean force;
+
+   @Override
+   public Object execute(ActionContext context) throws Exception {
+      super.execute(context);
+
+      initLogging(force, new File(getBrokerInstance()));
+
+      return null;
+   }
+
+
+   public static void initLogging(boolean force, File brokerInstance) throws 
Exception {
+      File etc = new File(brokerInstance, "etc");
+      File newLogging = new File(etc, Create.ETC_LOG4J2_PROPERTIES);
+
+      if (!force && newLogging.exists()) {
+         System.err.println("A configuration file " + 
newLogging.getAbsolutePath() + " already exists! Use the option -f if you want 
to re-initialize it");
+         return;
+      }
+
+      Create.write("etc/" + Create.ETC_LOG4J2_PROPERTIES, newLogging, 
Collections.emptyMap(), false, force, "utf-8");
+   }
+
+   public static void verifyOlderLogging(File fileInstance) throws Exception {
+      File etc = new File(fileInstance, "etc");
+      File newLogging = new File(etc, Create.ETC_LOG4J2_PROPERTIES);
+      File oldLogging = new File(etc, OLD_LOG_NAME);
+
+      if (oldLogging.exists() && !newLogging.exists()) {
+         logger.warn("Logging not initialized!");
+         StringWriter out    = new StringWriter();
+         PrintWriter writer = new PrintWriter(out);
+         writer.println("It seems you are migrating a previous version of an 
artemis instance without the new log4j configuration");
+         writer.println();
+         writer.printf("A new logging configuration is being created at %s", 
newLogging.getAbsolutePath());
+         writer.println();
+         writer.printf("The older configuration file %s should be manually 
removed.", oldLogging.getAbsolutePath());
+         ActionContext.system().out.println(out);
+
+         initLogging(false, fileInstance);
+      }

Review Comment:
   This isnt what we discussed recently. We said it should just look for the 
_old logging.properties_ file existing and warn if that was still present, 
noting that it should be removed and replaced with appropriate new Log4J2 
config, with the warning suggesting you could use the new _'artemis 
init-logging'_ command to create a log4j2.properties file in the instance dir 
the same as the 'artemis create' command would have made if used.
   
   This still just looks to create a new logging config file itself (itself a 
bit odd for a 'verifyOlderLogging' method), even though it doesnt know if Log4J 
has already been appropriately configured by one of many many other possible 
valid routes. Creating a new log4j2.properties file may even interfere with 
some of those other valid configs, or may have no effect in the presence of 
them (there is a long precedence order). We also have no idea what was in the 
old logging.config and thus whether the new default file is appropriate.
   
   I really think we should just avoid screwing with the config automatically 
and just make it clear they have old config in place and need to replace it.
   
   The existing versions.md upgrade documentation notes could also be changed 
to indicate use of the new init-logging command rather than the 'example file 
can be downloaded here' suggestion there currently.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 815175)
    Time Spent: 7h 40m  (was: 7.5h)

> switch to using SLF4J for logging API and use Log4j 2 for broker distribution
> -----------------------------------------------------------------------------
>
>                 Key: ARTEMIS-4020
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-4020
>             Project: ActiveMQ Artemis
>          Issue Type: Improvement
>            Reporter: Robbie Gemmell
>            Assignee: Robbie Gemmell
>            Priority: Major
>             Fix For: 2.27.0
>
>          Time Spent: 7h 40m
>  Remaining Estimate: 0h
>
> Switch to using [SLF4J|https://www.slf4j.org/] as the logging API for the 
> code base, with end-uses supplying and configuring an SLF4J-supporting 
> logging implementation of their choice based on their needs.
> For the client, applications will need to supply an SLF4J binding to a 
> logging implementation of their choice to enable logging. An example of doing 
> so using [Log4J 2|https://logging.apache.org/log4j/2.x/manual/index.html] is 
> given in (/will be, once the release is out) the [client logging 
> documentation|https://activemq.apache.org/components/artemis/documentation/latest/logging.html#logging-in-a-client-application].
> For the broker, the assembly distribution will include [Log4J 
> 2|https://logging.apache.org/log4j/2.x/manual/index.html] as its logging 
> implentation, with the "artemis create" CLI command used to create broker 
> instances now creating a log4j2.properties configuration within the 
> <broker-instance>/etc/ directory to configure Log4J. Details for upgrading an 
> existing broker-instance is given in (/will be, once the release is out) the 
> [version upgrade 
> documentation|https://activemq.apache.org/components/artemis/documentation/latest/versions.html].



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to