Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot and JBoss 8 Wildfly log configuration application

I have a Spring boot application prepare to be a WAR. It deploys without problems on Tomcat 8 (embedded or standalone) as well as on JBoss 8 Wildfly.
But while on Tomcat we have had configured working logback configuration on JBoos it does not work any more.

I have tried few different suggested solutions:
https://stackoverflow.com/a/21887529/3997870
https://stackoverflow.com/a/23080264/3997870

The best which I have found was to add to my project WEB-INF/jboss-deployment-structure.xml with

<jboss-deployment-structure>
 <deployment>
  <!-- exclude-subsystem prevents a subsystems deployment unit processors running on a deployment -->
  <!-- which gives basically the same effect as removing the subsystem, but it only affects single deployment -->
  <exclude-subsystems>
   <subsystem name="logging" />
  </exclude-subsystems>
 </deployment>
</jboss-deployment-structure>

but still it does not solve problem completely. In the logs I have same line twice (not because of logback configuration because on Tomcat worked properly) and also double info about time, level, thread was printed in first record.

[2014-11-26 15:28:42,605] [INFO ] [MSC service thread 1-3        ] [stdout] [NONE      ] [2014-11-26 15:28:42.605  INFO 8228 --- [vice thread 1-3] o.s.boot.SpringApplication               : Starting application on LCJLT306 with PID 8228 (started by Piotr.Konczak in D:\servers\wildfly-8.2.0.Final\bin)
]
[2014-11-26 15:28:42,605] [INFO ] [MSC service thread 1-3        ] [o.s.boot.SpringApplication] [NONE      ] [Starting application on LCJLT306 with PID 8228 (started by Piotr.Konczak in D:\servers\wildfly-8.2.0.Final\bin)]

As you can see in above example first record contains somehow additional timestamp, level and thread (I guess add by Wildfly during some redirect) while the second line is proper and expected.

My logback config has 2 parts - 1st inside app and 2nd outside app to make it possible to reconfigure in environments).
Inside the classpath:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml" />
    <include file="/opt/appName/config/appNameLogConfig.xml" />
</configuration>

Outside the app (included one):

<?xml version="1.0" encoding="UTF-8"?>
<included>

    <property name="DESTINATION_FOLDER" value="/opt/appName/logs" />
    <property name="FILE_NAME" value="AppName" />

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${DESTINATION_FOLDER}/${FILE_NAME}.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--daily rollover-->
            <fileNamePattern>${DESTINATION_FOLDER}/${FILE_NAME}.%d{yyyy-MM-dd}.log</fileNamePattern>
        </rollingPolicy>

        <encoder>
            <pattern>%-5level %date %-30thread %-30logger{30} [%-10mdc{requestId:-NONE}] %msg%n</pattern>
        </encoder>
    </appender>

    <logger name="org.springframework" level="INFO"/>
    <logger name="org.hibernate" level="INFO"/>
    <logger name="com.wordnik" level="INFO"/>
    <logger name="com.mangofactory" level="INFO"/>
    <logger name="com.company.appName" level="INFO"/>

    <root level="INFO">
        <appender-ref ref="FILE" />
    </root>
</included>

Does anyone see possible reason or misconfiguration?

like image 653
Piotr Kończak Avatar asked Nov 26 '14 15:11

Piotr Kończak


People also ask

Can we configure JBoss in spring boot?

With this configuration, the application is ready to deploy to any external application server. Once this is done, you can package your Spring Boot application as a war and deploy it to the JBoss server. To do that, you need to run mvn clean package , which will generate the war file.

Does spring boot use WildFly?

For most of the time deploying Spring Boot on application server like WildFly does not actually makes sense since embedded servers (Tomcat by default, Jetty,...) are part of Spring Boot itself. Deploying Spring Boot project to WildFly will be divided into three parts: Setting up WildFly (standalone edition)

What does WildFly use for logging?

By default WildFly uses a periodic log handler and will create a log for every calendar day. This is different than WebSphere or Jboss, and may not be the desired format for many customers. Luckily WildFly has highly customizable logging. Open the WildFly Admin Console (http://<host>:9990/console by default).


1 Answers

I know it is a little bit late but, if some of you face this problem, an alternative is: Don't disable the whole logging subsystem, instead just exclude slf4j libraries provided by JBoss/Wildfly, to use the one used by spring-boot.

<jboss-deployment-structure>
  <deployment>
    <exclusions>
      <module name='org.slf4j'/>
      <module name='org.slf4j.impl'/>
    </exclusions>
  </deployment>
</jboss-deployment-structure>

Hope helps somebody.

like image 131
carpinchosaurio Avatar answered Oct 26 '22 22:10

carpinchosaurio