0 Replies Latest reply on Nov 1, 2016 3:04 PM by Steve Gorman

    Wildfly 9 + spring-boot  Using  slf4j+log4j2 logs twice

    Steve Gorman Newbie

      I have configure a war that works as expected when deployed, displaying the expected "Greetings" in my browser. I then added slf4j+log4j2 by following tutorials with much trial and error. When I use my logger I get my log message formatted as I have instructed in my log4j2.xml file so I know things in general are working. However, I am getting two entries in my wildfly console that look like this...

       

      14:44:13,104 INFO  [com.ham.bone.GreetingController] (default task-11) Test Logging!

      [2016-11-01 14:44:13.104] boot - 7564  INFO [default task-11] --- GreetingController: Test Logging!

       

      Obviously the first line of logging is my own class but the second is not. I am assuming it is coming from spring-boot-starter. How do I disable it?

       

      Configuration:

      I have made no modifications to standalone.xml

      pom.xml:

       

      <dependencies>
        <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
        <exclusion>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
        <exclusion>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        </exclusion>
        <exclusion>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
        <exclusion>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-validation</artifactId>
        </exclusion>
        </exclusions>
        </dependency>
      
        <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        </dependency>
        <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        </dependency>
        <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        </dependency>
      
        <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>4.0.0-b01</version>
        <scope>provided</scope>
        </dependency>
      </dependencies>

       

      jboss-deployment-structure:

      <deployment>
        <exclusions>
        <module name="org.apache.log4j" />
        </exclusions>
        <exclude-subsystems>
        <subsystem name="logging"/>
        </exclude-subsystems>
        <dependencies>
        <module name="org.slf4j" />
        </dependencies>
      </deployment>
      

      log4j2.xml:

      <Configuration status="WARN">
        <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
        <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
        </Console>
        <File name="MyFile" fileName="all.log" immediateFlush="false" append="false" relative-to="jboss.server.log.dir" >
        <PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </File>
        </Appenders>
        <Loggers>
        <Root level="DEBUG">
        <AppenderRef ref="Console" />
        </Root>
        </Loggers>
      </Configuration>
      

      Spring Controller

      @RestController
      public class GreetingController {

       

         private static final String template = "Hello, %s!";
        private final AtomicLong counter = new AtomicLong();
        protected final Logger logger = LoggerFactory.getLogger(GreetingController.class);

         @RequestMapping("/greeting")

         public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {

         logger.info("Test Logging!");

        return new Greeting(counter.incrementAndGet(),
         String.format(template, name));
         }

      }

       

      What have I missed?

       

      P.S

      Thank you!