Wildfly-Swarm – Logging

Tried this with Wildfly Swarm version 2017.8.1. Seems like in newer versions a new approach is used.

I added the logging artifact in the maven build file:

<dependency>
   <groupId>org.wildfly.swarm</groupId>
   <artifactId>logging</artifactId>
   <version>2017.8.1</version>
</dependency>

In /src/main/resources/ a file logging.properties with the following content is setup:

logger.level=INFO
logger.handlers=FILE

handler.FILE=org.jboss.logmanager.handlers.FileHandler
handler.FILE.level=INFO
handler.FILE.formatter=PATTERN
handler.FILE.properties=append,fileName,autoFlush
handler.FILE.append=false
handler.FILE.autoFlush=true
handler.FILE.fileName=./myapp.log

formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter
formatter.PATTERN.properties=pattern
formatter.PATTERN.pattern=%d{HH:mm:ss,SSS} %-5p [%c] %s%E%n

In your code, you setup and use org.jboss.logging.Logger instances like this:

Logger LOG = Logger.getLogger(MyClass.class);
LOG.info("Example log message");
LOG.error("Something strange happend", new Exception() );

Wildfly-Swarm – Basic setup

Tried this with Wildfly Swarm version 2017.8.1.

In the maven pom.xml the following entries are added.

<dependencyManagement>
   <dependencies>
      <dependency>
         <groupId>org.wildfly.swarm</groupId>
         <artifactId>bom-all</artifactId>
         <version>2017.8.1</version>
         <scope>import</scope>
         <type>pom</type>
      </dependency>
   </dependencies>
</dependencyManagement>

 

For building the uberjar or executing the plugin needs to be added.

<plugins>
   <plugin>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>wildfly-swarm-plugin</artifactId>
      <version>${version.wildfly.swarm}</version>
      <executions>
         <execution>
            <goals>
               <goal>package</goal>
            </goals>
         </execution>
      </executions>
   </plugin>
</plugins>

 

Creation of the uberjar happens, when you call package goal:

mvn package

 

The uberjar could be found in the target folder. Execute it with java -jar:

java -jar ./target/myapp-swarm.jar

 

If you want to debug your code, run it from maven, add the following parameter to your maven command and do a remote debugging session in your ide. Beware, that the Wildfly-Swarm process stops until a connection is open. Here we open a debug port on 8888.

maven run -Ddebug=8888