+ * For {@link #isEnabled(Level)} {@link org.jboss.logging.Logger.Level#TRACE} is ignored and + * {@link org.jboss.logging.Logger.Level#FATAL} + * is treated as an {@link Log#error(CharSequence, Throwable) error}. + *
+ *+ * For the log methods, {@link org.jboss.logging.Logger.Level#TRACE} is treated as a {@link Log#debug(CharSequence, Throwable) + * debug} + * and {@link org.jboss.logging.Logger.Level#FATAL} is treated as {@link Log#error(CharSequence, Throwable) error}. + *
+ * + * @author James R. Perkins + */ +public class MavenJBossLogger extends Logger { + private final Log mavenLogger; + + public MavenJBossLogger(final Log mavenLogger) { + super(mavenLogger.toString()); + this.mavenLogger = mavenLogger; + } + + @Override + protected void doLog(final Level level, final String loggerClassName, final Object message, final Object[] parameters, + final Throwable thrown) { + final String msg = parameters == null ? String.valueOf(message) + : MessageFormat.format(String.valueOf(message), parameters); + doMavenLog(level, msg, thrown); + } + + @Override + protected void doLogf(final Level level, final String loggerClassName, final String format, final Object[] parameters, + final Throwable thrown) { + final String msg = String.format(format, parameters); + doMavenLog(level, msg, thrown); + } + + @Override + public boolean isEnabled(final Level level) { + switch (level) { + case DEBUG: + return mavenLogger.isDebugEnabled(); + case INFO: + return mavenLogger.isInfoEnabled(); + case WARN: + return mavenLogger.isWarnEnabled(); + case FATAL: + case ERROR: + return mavenLogger.isErrorEnabled(); + } + return false; + } + + private void doMavenLog(final Level level, final String msg, final Throwable thrown) { + switch (level) { + case TRACE: + case DEBUG: + if (thrown == null) { + mavenLogger.debug(msg); + } else { + mavenLogger.debug(msg, thrown); + } + break; + case WARN: + if (thrown == null) { + mavenLogger.warn(msg); + } else { + mavenLogger.warn(msg, thrown); + } + break; + case FATAL: + case ERROR: + if (thrown == null) { + mavenLogger.error(msg); + } else { + mavenLogger.error(msg, thrown); + } + break; + default: + if (thrown == null) { + mavenLogger.info(msg); + } else { + mavenLogger.info(msg, thrown); + } + } + } +} diff --git a/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java b/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java index 79375ccd..867e9236 100644 --- a/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java +++ b/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java @@ -53,6 +53,13 @@ * @author jfdenise */ abstract class AbstractProvisionServerMojo extends AbstractMojo { + static { + // This is odd, but if not set we should set the JBoss Logging provider to slf4j as that is what Maven uses + final String provider = System.getProperty("org.jboss.logging.provider"); + if (provider == null || provider.isBlank()) { + System.setProperty("org.jboss.logging.provider", "slf4j"); + } + } @Component RepositorySystem repoSystem; diff --git a/plugin/src/main/java/org/wildfly/plugin/provision/PackageServerMojo.java b/plugin/src/main/java/org/wildfly/plugin/provision/PackageServerMojo.java index 71df8495..e7de269c 100644 --- a/plugin/src/main/java/org/wildfly/plugin/provision/PackageServerMojo.java +++ b/plugin/src/main/java/org/wildfly/plugin/provision/PackageServerMojo.java @@ -36,13 +36,13 @@ import org.wildfly.plugin.cli.BaseCommandConfiguration; import org.wildfly.plugin.cli.CliSession; import org.wildfly.plugin.cli.OfflineCommandExecutor; +import org.wildfly.plugin.common.MavenJBossLogger; import org.wildfly.plugin.common.PropertyNames; import org.wildfly.plugin.common.StandardOutput; import org.wildfly.plugin.common.Utils; import org.wildfly.plugin.deployment.MojoDeploymentException; import org.wildfly.plugin.deployment.PackageType; import org.wildfly.plugins.core.bootablejar.BootableJarSupport; -import org.wildfly.plugins.core.bootablejar.Log; /** * Provision a server, copy extra content and deploy primary artifact if it @@ -381,29 +381,7 @@ private void packageBootableJar(Path jbossHome, GalleonProvisioningConfig active BootableJarSupport.packageBootableJar(targetJarFile, targetPath, activeConfig, jbossHome, artifactResolver, - new MvnMessageWriter(getLog()), new Log() { - @Override - public void warn(String string) { - getLog().warn(string); - } - - @Override - public void debug(String string) { - if (getLog().isDebugEnabled()) { - getLog().debug(string); - } - } - - @Override - public void error(String string) { - getLog().error(string); - } - - @Override - public void info(String string) { - getLog().info(string); - } - }); + new MvnMessageWriter(getLog()), new MavenJBossLogger(getLog())); attachJar(targetJarFile); getLog().info("Bootable JAR packaging DONE. To run the server: java -jar " + targetJarFile);