refactor(gateway-vertx) Use log4j2 by default.
MODIFY
common/logging/log4j2/src/main/java/io/apiman/common/logging/log4j2/Log4j2LoggerFactory.java
common/logging/log4j2/src/main/java/io/apiman/common/logging/log4j2/Log4j2LoggerFactory.java
@@ -17,7 +17,9 @@ package io.apiman.common.logging.log4j2;
import io.apiman.common.logging.IApimanLogger;
import io.apiman.common.logging.IDelegateFactory;
+
import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.message.FormattedMessageFactory;
/**
* Log4j2 logger factory.
@@ -27,11 +29,11 @@ import org.apache.logging.log4j.LogManager;
public class Log4j2LoggerFactory implements IDelegateFactory {
@Override
public IApimanLogger createLogger(String name) {
- return new Log4j2LoggerImpl(LogManager.getLogger(name));
+ return new Log4j2LoggerImpl(LogManager.getLogger(name, new FormattedMessageFactory()));
}
@Override
public IApimanLogger createLogger(Class<?> klazz) {
- return new Log4j2LoggerImpl(LogManager.getLogger(klazz));
+ return new Log4j2LoggerImpl(LogManager.getLogger(klazz, new FormattedMessageFactory()));
}
}

MODIFY
distro/vertx/src/main/resources/overlay/configs/conf-es.json
distro/vertx/src/main/resources/overlay/configs/conf-es.json
},
"logger-factory": {
- "class": "io.apiman.gateway.platforms.vertx3.common.config.VertxLoggerDelegate",
+ "class": "io.apiman.gateway.platforms.vertx3.logging.VertxLoggerDelegate",
"config": {
}

MODIFY
gateway/platforms/vertx3/vertx3/pom.xml
gateway/platforms/vertx3/vertx3/pom.xml
<groupId>${project.groupId}</groupId>
<artifactId>apiman-common-logging-core</artifactId>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>apiman-common-logging-log4j2</artifactId>
+ </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apiman-gateway-api-rest</artifactId>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
+ <!-- For custom Vert.x log4j2 delegate code -->
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ </dependency>
<!-- Spec Only -->
<dependency>

MODIFY
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/ApimanLauncher.java
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/ApimanLauncher.java
package io.apiman.gateway.platforms.vertx3;
+import io.apiman.gateway.platforms.vertx3.logging.ApimanLog4j2LogDelegateFactory;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Launcher;
import io.vertx.core.Vertx;
@@ -26,6 +27,13 @@ import io.vertx.core.json.JsonObject;
public class ApimanLauncher extends VertxCommandLauncher implements VertxLifecycleHooks {
+ // Ensure we're in control of logging.
+ static {
+ if (System.getProperty("vertx.logger-delegate-factory-class-name") == null) { //$NON-NLS-1$
+ System.setProperty("vertx.logger-delegate-factory-class-name", ApimanLog4j2LogDelegateFactory.class.getCanonicalName()); //$NON-NLS-1$
+ }
+ }
+
/**
* Main entry point.
*

MODIFY
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/common/config/VertxEngineConfig.java
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/common/config/VertxEngineConfig.java
@@ -41,6 +41,7 @@ import io.apiman.gateway.platforms.vertx3.common.verticles.VerticleType;
import io.apiman.gateway.platforms.vertx3.connector.ConnectorFactory;
import io.apiman.gateway.platforms.vertx3.engine.VertxPluginRegistry;
import io.apiman.gateway.platforms.vertx3.i18n.Messages;
+import io.apiman.gateway.platforms.vertx3.logging.VertxLoggerDelegate;
import io.vertx.core.json.JsonObject;
import java.util.AbstractMap;

ADD
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/logging/ApimanLog4j2LogDelegate.java
+package io.apiman.gateway.platforms.vertx3.logging;
+
+import io.vertx.core.logging.Log4j2LogDelegate;
+import io.vertx.core.logging.Logger;
+import io.vertx.core.spi.logging.LogDelegate;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.message.FormattedMessageFactory;
+import org.apache.logging.log4j.message.MessageFormatMessage;
+import org.apache.logging.log4j.spi.ExtendedLogger;
+
+/**
+ * Modification of {@link Log4j2LogDelegate} to use {@link FormattedMessageFactory}.
+ */
+public class ApimanLog4j2LogDelegate implements LogDelegate {
+
+ private ExtendedLogger logger;
+ final static String FQCN = Logger.class.getCanonicalName();
+
+ ApimanLog4j2LogDelegate(final String name) {
+ logger = (ExtendedLogger) org.apache.logging.log4j.LogManager.getLogger(name, new FormattedMessageFactory());
+ }
+
+ @Override
+ public boolean isInfoEnabled() {
+ return logger.isInfoEnabled();
+ }
+
+ @Override
+ public boolean isDebugEnabled() {
+ return logger.isDebugEnabled();
+ }
+
+ @Override
+ public boolean isTraceEnabled() {
+ return logger.isTraceEnabled();
+ }
+
+ @Override
+ public void fatal(final Object message) {
+ log(Level.FATAL, message);
+ }
+
+ @Override
+ public void fatal(final Object message, final Throwable t) {
+ log(Level.FATAL, message, t);
+ }
+
+ @Override
+ public void error(final Object message) {
+ log(Level.ERROR, message);
+ }
+
+ @Override
+ public void error(Object message, Object... params) {
+ log(Level.ERROR, message.toString(), params);
+ }
+
+ @Override
+ public void error(final Object message, final Throwable t) {
+ log(Level.ERROR, message, t);
+ }
+
+ @Override
+ public void error(Object message, Throwable t, Object... params) {
+ log(Level.ERROR, message.toString(), t, params);
+ }
+
+ @Override
+ public void warn(final Object message) {
+ log(Level.WARN, message);
+ }
+
+ @Override
+ public void warn(Object message, Object... params) {
+ log(Level.WARN, message.toString(), params);
+ }
+
+ @Override
+ public void warn(final Object message, final Throwable t) {
+ log(Level.WARN, message, t);
+ }
+
+ @Override
+ public void warn(Object message, Throwable t, Object... params) {
+ log(Level.WARN, message.toString(), t, params);
+ }
+
+ @Override
+ public void info(final Object message) {
+ log(Level.INFO, message);
+ }
+
+ @Override
+ public void info(Object message, Object... params) {
+ log(Level.INFO, message.toString(), params);
+ }
+
+ @Override
+ public void info(final Object message, final Throwable t) {
+ log(Level.INFO, message, t);
+ }
+
+ @Override
+ public void info(Object message, Throwable t, Object... params) {
+ log(Level.INFO, message.toString(), t, params);
+ }
+
+ @Override
+ public void debug(final Object message) {
+ log(Level.DEBUG, message);
+ }
+
+ @Override
+ public void debug(Object message, Object... params) {
+ log(Level.DEBUG, message.toString(), params);
+ }
+
+ @Override
+ public void debug(final Object message, final Throwable t) {
+ log(Level.DEBUG, message, t);
+ }
+
+ @Override
+ public void debug(Object message, Throwable t, Object... params) {
+ log(Level.DEBUG, message.toString(), t, params);
+ }
+
+ @Override
+ public void trace(final Object message) {
+ log(Level.TRACE, message);
+ }
+
+ @Override
+ public void trace(Object message, Object... params) {
+ log(Level.TRACE, message.toString(), params);
+ }
+
+ @Override
+ public void trace(final Object message, final Throwable t) {
+ log(Level.TRACE, message.toString(), t);
+ }
+
+ @Override
+ public void trace(Object message, Throwable t, Object... params) {
+ log(Level.TRACE, message.toString(), t, params);
+ }
+
+ private void log(Level level, Object message) {
+ log(level, message, null);
+ }
+
+ private void log(Level level, Object message, Throwable t) {
+ logger.logIfEnabled(FQCN, level, null, message, t);
+ }
+
+ private void log(Level level, String message, Object... params) {
+ logger.logIfEnabled(FQCN, level, null, message, params);
+ }
+
+ private void log(Level level, String message, Throwable t, Object... params) {
+ logger.logIfEnabled(FQCN, level, null, new MessageFormatMessage(message, params), t);
+ }
+
+ @Override
+ public Object unwrap() {
+ return logger;
+ }
+}
\ No newline at end of file

ADD
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/logging/ApimanLog4j2LogDelegateFactory.java
+package io.apiman.gateway.platforms.vertx3.logging;
+
+import io.vertx.core.spi.logging.LogDelegate;
+import io.vertx.core.spi.logging.LogDelegateFactory;
+
+public class ApimanLog4j2LogDelegateFactory implements LogDelegateFactory {
+ @Override
+ public LogDelegate createDelegate(final String name) {
+ return new ApimanLog4j2LogDelegate(name);
+ }
+}
\ No newline at end of file

RENAME
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/common/config/VertxLoggerDelegate.java
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/logging/VertxLoggerDelegate.java
* limitations under the License.
*/
-package io.apiman.gateway.platforms.vertx3.common.config;
+package io.apiman.gateway.platforms.vertx3.logging;
import io.apiman.common.logging.IApimanLogger;
import io.apiman.common.logging.IDelegateFactory;
@@ -23,6 +23,7 @@ import io.vertx.core.logging.LoggerFactory;
public class VertxLoggerDelegate implements IDelegateFactory {
+ // For the Apiman logger system.
@Override
public IApimanLogger createLogger(String name) {
return new VertxApimanLogger(LoggerFactory.getLogger(name));

MODIFY
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/verticles/ApimanVerticleBase.java
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/verticles/ApimanVerticleBase.java
@@ -18,7 +18,6 @@ package io.apiman.gateway.platforms.vertx3.verticles;
import io.apiman.common.util.SimpleStringUtils;
import io.apiman.gateway.platforms.vertx3.common.config.VertxEngineConfig;
import io.apiman.gateway.platforms.vertx3.common.verticles.VerticleType;
-import io.apiman.gateway.platforms.vertx3.i18n.Messages;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.logging.Logger;
@@ -40,10 +39,7 @@ public abstract class ApimanVerticleBase extends AbstractVerticle {
@Override
public void start(Future<Void> startFuture) {
apimanConfig = getEngineConfig();
-
- log.info(Messages.getString("ApimanVerticleBase.starting_verticle") + this.getClass().getName() + "\n" +
- Messages.getString("ApimanVerticleBase.type") + verticleType() + "\n" +
- Messages.getString("ApimanVerticleBase.uuid") + uuid + "\n");
+ log.info("Starting verticle: {0}. UUID: {1}.", verticleType(), uuid);
}
/**

MODIFY
gateway/test/src/test/resources/vertx3/conf-es.json
gateway/test/src/test/resources/vertx3/conf-es.json
},
"logger-factory": {
- "class": "io.apiman.gateway.platforms.vertx3.common.config.VertxLoggerDelegate",
+ "class": "io.apiman.gateway.platforms.vertx3.logging.VertxLoggerDelegate",
"config": {}
},

MODIFY
gateway/test/src/test/resources/vertx3/conf-file.json
gateway/test/src/test/resources/vertx3/conf-file.json
},
"logger-factory": {
- "class": "io.apiman.gateway.platforms.vertx3.common.config.VertxLoggerDelegate",
+ "class": "io.apiman.gateway.platforms.vertx3.logging.VertxLoggerDelegate",
"config": {}
},

MODIFY
gateway/test/src/test/resources/vertx3/conf-mem.json
gateway/test/src/test/resources/vertx3/conf-mem.json
},
"logger-factory": {
- "class": "io.apiman.gateway.platforms.vertx3.common.config.VertxLoggerDelegate",
+ "class": "io.apiman.gateway.platforms.vertx3.logging.VertxLoggerDelegate",
"config": {}
},

MODIFY
gateway/test/src/test/resources/vertx3/conf-shared-global-data.json
gateway/test/src/test/resources/vertx3/conf-shared-global-data.json
},
"logger-factory": {
- "class": "io.apiman.gateway.platforms.vertx3.common.config.VertxLoggerDelegate",
+ "class": "io.apiman.gateway.platforms.vertx3.logging.VertxLoggerDelegate",
"config": {}
},

MODIFY
pom.xml
pom.xml
<version.org.apache.httpcomponents.httpclient>4.5</version.org.apache.httpcomponents.httpclient>
<version.org.apache.httpcomponents.httpcore>4.4.1</version.org.apache.httpcomponents.httpcore>
<version.org.apache.httpcomponents.httpasyncclient>4.1</version.org.apache.httpcomponents.httpasyncclient>
- <version.org.apache.logging.log4j>2.2</version.org.apache.logging.log4j>
+ <version.org.apache.logging.log4j>2.8.2</version.org.apache.logging.log4j>
<version.org.eclipse.jetty>9.2.20.v20161216</version.org.eclipse.jetty>
<version.org.glassfish.javax.el>3.0.0</version.org.glassfish.javax.el>
<version.org.elasticsearch>1.7.2</version.org.elasticsearch>
<version.org.mvel>2.2.7.Final</version.org.mvel>
<version.org.osgi>4.2.0</version.org.osgi>
<version.org.picketbox>4.9.6.Final</version.org.picketbox>
- <version.org.slf4j>1.7.7</version.org.slf4j>
+ <version.org.slf4j>1.7.21</version.org.slf4j>
<version.io.netty>4.1.8.Final</version.io.netty>
<version.io.swagger>1.5.7</version.io.swagger>
<version.xmlunit>1.6</version.xmlunit>

refactor(gateway-vertx) Use log4j2 by default.