[
https://issues.apache.org/jira/browse/ARTEMIS-4020?focusedWorklogId=813312&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-813312
]
ASF GitHub Bot logged work on ARTEMIS-4020:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 29/Sep/22 11:47
Start Date: 29/Sep/22 11:47
Worklog Time Spent: 10m
Work Description: gemmellr commented on code in PR #4237:
URL: https://github.com/apache/activemq-artemis/pull/4237#discussion_r983387224
##########
artemis-junit/src/main/java/org/apache/activemq/artemis/junit/EmbeddedActiveMQResource.java:
##########
@@ -66,11 +67,10 @@
* </code></pre>
*/
public class EmbeddedActiveMQResource extends ExternalResource {
+ private static final Logger logger =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Review Comment:
Ditto
##########
artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/ssl/DefaultSSLContextFactory.java:
##########
@@ -15,18 +15,23 @@
*/
package org.apache.activemq.artemis.core.remoting.impl.ssl;
+import java.lang.invoke.MethodHandles;
import java.util.Map;
import javax.net.ssl.SSLContext;
import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
import org.apache.activemq.artemis.spi.core.remoting.ssl.SSLContextConfig;
import org.apache.activemq.artemis.spi.core.remoting.ssl.SSLContextFactory;
import org.apache.activemq.artemis.utils.ConfigurationHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Simple SSLContextFactory for use in NettyConnector and NettyAcceptor.
*/
public class DefaultSSLContextFactory implements SSLContextFactory {
+ private static final Logger logger =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Review Comment:
Ditto
##########
artemis-junit/src/main/java/org/apache/activemq/artemis/junit/EmbeddedJMSResource.java:
##########
@@ -78,6 +79,7 @@
*/
@Deprecated
public class EmbeddedJMSResource extends ExternalResource {
+ private static final Logger logger =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Review Comment:
This adds 'logger' but the class also has and is still using "log" below.
##########
artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/scram/SCRAMServerSASLFactory.java:
##########
@@ -44,14 +44,16 @@
import org.apache.activemq.artemis.spi.core.security.scram.UserData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.lang.invoke.MethodHandles;
/**
* abstract class that implements the SASL-SCRAM authentication scheme,
concrete implementations
* must supply the {@link SCRAM} type to use and be register via SPI
*/
public abstract class SCRAMServerSASLFactory implements ServerSASLFactory {
- private final Logger logger = LoggerFactory.getLogger(getClass());
+ private static final Logger logger =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Review Comment:
This changes the name of the Logger, which is used for different mechanisms
and passed around to related objects. The child classes should be changed to
have their own static Logger and pass it via the constructor rather than
creating here, to retain existing behaviour and allow distinguishing the
mechanism the logging is actually for.
##########
tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/logging/AssertionLoggerTest.java:
##########
@@ -64,7 +65,7 @@ public void testInfoAMQP() throws Exception {
private void validateLogging(Class<?> clazz) {
String randomLogging = RandomUtil.randomString();
- Logger logging = LoggerFactory.getLogger(clazz);
+ Logger logging =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Review Comment:
This breaks the intent of the method, it should be restored.
##########
artemis-junit/src/main/java/org/apache/activemq/artemis/junit/AbstractActiveMQClientResource.java:
##########
@@ -27,10 +27,11 @@
import org.junit.rules.ExternalResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.lang.invoke.MethodHandles;
public abstract class AbstractActiveMQClientResource extends ExternalResource {
- Logger log = LoggerFactory.getLogger(this.getClass());
+ private static final Logger logger =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Review Comment:
This will change the logger name from being the specific non-abstract
childs, to the abstract parent class.
May not be an issue, since the 'start' logging using it actually prints the
class simple name, but just noting the difference.
Could pass in the logger to use to retain the existing naming behaviour.
##########
artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java:
##########
@@ -814,7 +815,7 @@ public void run() {
}
private static void checkCriticalAnalyzerLogging() {
- Logger criticalLogger =
LoggerFactory.getLogger("org.apache.activemq.artemis.utils.critical");
+ Logger criticalLogger =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Review Comment:
This changes the logger name used for the check to the wrong value, the one
for ActiveMQServerImpl (and so also duplicates the class-level logger), rather
than "org.apache.activemq.artemis.utils.critical" used before, which is what is
also referenced in the log4j2.properties config.
Should be changed to a value derived from the declaration of the original
logger elsewhere (maybe declared as a constant).
##########
artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/AbstractPrincipalLoginModule.java:
##########
@@ -31,12 +31,13 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.lang.invoke.MethodHandles;
/**
* Abstract login module that uses an external authenticated principal
*/
public abstract class AbstractPrincipalLoginModule implements AuditLoginModule
{
- private final Logger logger = LoggerFactory.getLogger(getClass());
+ private static final Logger logger =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Review Comment:
Similar to earlier comments, this changes the logger used by the subclasses
to all be the same name, making it no longer possible to tell which one the
logging related to. Should instead make them pass in their own static logger to
retain existing logging behaviour.
##########
artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/FileBasedNodeManager.java:
##########
@@ -32,14 +32,15 @@
import org.apache.activemq.artemis.utils.UUIDGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.lang.invoke.MethodHandles;
import static java.nio.file.StandardOpenOption.CREATE;
import static java.nio.file.StandardOpenOption.READ;
import static java.nio.file.StandardOpenOption.WRITE;
public abstract class FileBasedNodeManager extends NodeManager {
- private static final Logger LOGGER =
LoggerFactory.getLogger(FileBasedNodeManager.class);
+ private static final Logger logger =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Review Comment:
Should be deleted instead; name changed without any other uses changing, so
its unused.
##########
artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/ssl/DefaultOpenSSLContextFactory.java:
##########
@@ -16,27 +16,32 @@
*/
package org.apache.activemq.artemis.core.remoting.impl.ssl;
+import java.lang.invoke.MethodHandles;
import java.util.Map;
import io.netty.handler.ssl.SslContext;
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector;
import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
import org.apache.activemq.artemis.spi.core.remoting.ssl.OpenSSLContextFactory;
import org.apache.activemq.artemis.spi.core.remoting.ssl.SSLContextConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Default {@link OpenSSLContextFactory} for use in {@link NettyConnector} and
NettyAcceptor.
*/
public class DefaultOpenSSLContextFactory implements OpenSSLContextFactory {
+ private static final Logger logger =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Review Comment:
Since it is debug and really specific to this class, I think this is fine,
especially as having a logger in an interface seems ugly, but just noting that
this is changing the logger name used.
##########
artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java:
##########
@@ -172,17 +173,17 @@
*/
public abstract class ActiveMQTestBase extends Assert {
- private static final Logger log =
LoggerFactory.getLogger(ActiveMQTestBase.class);
+ private static final Logger log =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Review Comment:
Might be worth looking at why there are 3 identical Logger declarations in
this class (more below this one).
##########
tests/artemis-test-support/src/main/java/org/apache/activemq/transport/amqp/client/AmqpProtocolTracer.java:
##########
@@ -37,7 +39,7 @@
*/
public class AmqpProtocolTracer implements ProtocolTracer,
FrameBodyHandler<AmqpFrameValidator> {
- private static final Logger TRACE_FRAMES =
LoggerFactory.getLogger(AmqpProtocolTracer.class.getPackage().getName() +
".FRAMES");
+ private static final Logger logger =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Review Comment:
Noting it changes the logger name. Maybe not an issue as its only the test
client.
Issue Time Tracking
-------------------
Worklog Id: (was: 813312)
Time Spent: 4h 10m (was: 4h)
> 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
> Priority: Major
> Fix For: 2.27.0
>
> Time Spent: 4h 10m
> 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)