Spring boot and JBoss 8 Wildfly log configuration application - jboss

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?

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.

I am using my own logging configuration, log4j2 xml instead of spring's logging and faced the same issue with the Wildfly. I commented the whole subsytem system for over-riding that.

Related

Quartz 1.8.5 + OpenLiberty 18.0.0.4/ Websphere Liberty 17.0.0.4 java.lang.NoClassDefFoundError: oracle/sql/BLOB

we get the following exception when using quartz 1.8.5 and the liberty server. While using a tomcat-server (7.0.81) the exception doesn't occur.
java.lang.NoClassDefFoundError: oracle/sql/BLOB
at org.quartz.impl.jdbcjobstore.oracle.OracleDelegate.writeDataToBlob(OracleDelegate.java:642)
at org.quartz.impl.jdbcjobstore.oracle.OracleDelegate.insertJobDetail(OracleDelegate.java:207)
pom.xml
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>1.8.5</version>
</dependency>
<dependency>
<!-- ASYNC-METHOD-INVOCATION -->
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-oracle</artifactId>
<version>1.8.5</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>12.1.0.2.0</version>
<scope>provided</scope>
</dependency>
dataSource
<server>
<library id="oracleDriver">
<fileset dir="..\sw\oracle" includes="*.jar" scanInterval="120s" />
</library>
<!-- xa datasource -->
<dataSource id="ORACLE_DS_XA" jndiName="jdbc/xxx/xxx" pool-name="xxx">
<jdbcDriver libraryRef="oracleDriver" javax.sql.ConnectionPoolDataSource="oracle.jdbc.xa.client.OracleXADataSource" />
<properties.oracle URL="jdbc:oracle:thin:#localhost:1521:sid" password="user" user="password" />
<connectionManager minPoolSize="1" maxPoolSize="10" />
</dataSource>
<keyStore id="defaultKeyStore" password="password" />
</server>
What could be the reason for that exception? And how can we solve the problem?
Tell me if i should provide more information about our configuration.
TIA
I'm not really familiar with either, but if quartz is bundled in your application and needs access to the classes from your Oracle driver, then you need to expose the shared library to your application.
You'd do this by adding a <classloader> section to your <application> or <webapplication> block in your server.xml
E.g.
<application ...rest of your app configuration...>
<classloader commonLibraryRef="oracleDriver"/>
</application>
If you're currently deploying your app by putting it in the dropins directory, you'll have to change that to deploy your application to the apps directory instead and create an <application> or <webApplication> block in your server.xml.
Documentation links:
Deploying an app and adding the server.xml configuration
Reference for <application> element (includes classloader as a sub-element)
Reference for <webApplication> element (includes classloader as a sub-element)

Play framework (2.3.7) not using my logback configuration

I am using Play 2.3.7
I read the documentation here
https://www.playframework.com/documentation/2.3.x/SettingsLogger
I created a file called application-logger.xml (and as logger.xml) under my conf directory
<configuration>
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${application.home}/logs/foo.log</file>
<encoder>
<pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%coloredLevel %logger{15} - %message%n%xException{5}</pattern>
</encoder>
</appender>
<logger name="play" level="INFO">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</logger>
<logger name="application" level="INFO">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</logger>
<root level="off" />
</configuration>
Now I run my play application activator clean run and it prints nothing on the console if there is an error. there is no file 'foo.log' created as well.
Based on my reading of the documentation, I thought all my application code will use a logger called "application" and the play internal would use a logger called "play" so if I define appenders for these two loggers I will have everything on console and my file.
But that does not seem to be happening.
I have put the application-logger.xml file in conf directory next to application.conf file.
I also tried renaming my file to logger.xml but still it is just ignored.
Edit::
I even tried to run my application like
./activator -Dlogger.resource=logger.xml run
./activator -Dlogger.file=./conf/logger.xml run
But nothing can make the play framework pick up that file. nothing.
I was able to find a solution here
https://www.reddit.com/r/scala/comments/6q6vb3/why_is_it_such_a_big_deal_for_play_framework_to/
Basically when launching the app use the logback configuration setting
so activator -Dlogback.configurationFile=logger.xml run`
The play documentation setting -Dlogger.resource or -Dlogger.file does not work.
This can be the case with custom ApplicationLoader, it require update load with
LoggerConfigurator(context.environment.classLoader).foreach {
_.configure(context.environment, context.initialConfiguration, Map.empty)
}
https://www.playframework.com/documentation/2.6.x/SettingsLogger#Using-a-custom-application-loader
I run it from IntelliJ, and with
-Dlogger.resource=logback-test.xml works smoothly.

Debug Gatling Scala Code in Intellij with Maven Java Project

I didn't add a comment in this Debug Scala Post because in my opinion it was another setup.
I had a similiar problem with Maven instead of SBT. I used Maven because the complete Java project was built upon it and I only wanted to debug my Gatling Scala code. However I'm not able to debug the code with the IDE.
Here's what I tried:
Clean the built mvn clean install
Invalidate caches in IDEA with the menu button
Use println to see whether the code is reached - worked
Redeploy the project on the Glassfish
Delete the generated files in the Glassfish and redeploy
This is my current setup:
Maven 3.3.9
Glassfish Payara 4 build 163
IDEA 2016.3.4. built on January 31 2017
JDK 1.8.0_51
Gatling 2.2.3
Scala-Maven-Plug 3.2.2
My solution is as follows.
With the help of colleague I figured out that the main class in Engine from the Gatling tutorial can be used to debug out of Intellij.
I basically built the whole archetype and moved the following files into the corresponding folders:
src/test/resources/gatling.conf
src/test/scala/Engine.scala and IDEPathHelper
That did the trick for me.
If anybody is finding hard to this just create a logback.xml file under src/test/resources and mention the following according to your need:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
<immediateFlush>false</immediateFlush>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>../gatling.log</file>
<append>true</append>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
</encoder>
</appender>
<!-- Uncomment for logging ALL HTTP request and responses -->
<!-- <logger name="io.gatling.http.ahc" level="TRACE" /> -->
<!-- <logger name="io.gatling.http.response" level="TRACE" /> -->
<!-- Uncomment for logging ONLY FAILED HTTP request and responses -->
<logger name="io.gatling.http.ahc" level="DEBUG" />
<logger name="io.gatling.http.response" level="DEBUG" />
<root level="WARN">
<appender-ref ref="CONSOLE" />
</root>
<root level="WARN">
<appender-ref ref="FILE" />
</root>
</configuration>

How to configure tranquility to show debug log

I want to use tranquility and its Storm Bolt to send data to druid.So I wrote a storm topology(with dependency of tranquility) and compile it to a jar file, then use run storm with that jar file in local mode. Yet I came across problems: the storm bolt show's nothing wrong and the druid's overlord node log nothing. I feel like the overlord had not received data send by storm bolt.
I want to find out the problem. I did enable storm config's debug
conf.setDebug(true);
but it just show detailed information of every spout and bolt, it does not show tranquility's debug log info. I tried change storm's logback/cluster.xml to
<root level="DEBUG">
<appender-ref ref="A1"/>
</root>
But it seems do not work. I try add a log4j.xml in my project's top directory:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true"
xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="console" />
</root>
</log4j:configuration>
It does not work too.
I make some digging in tranquility's source code, and see tranquility depend on ladylog library which depend on log4j, so I thought adding a log4j.xml in project would enable the debug mode and can see the debug output of this BeamBot
I am totally confused, because now I wrote a jar that use tranquiity library which use loglady library which use log4j and my jar that run by storm which use logback. Could anyone give me some suggestions?
then use run storm with that jar file in local mode
Since you run the jar file in local mode, it makes no sense to modify logback/cluster.xml. Generally, Storm will read default configurations from the specific dependency like storm-core-0.9.4.jar under local mode, unless you change configurations manually in your topology. You should run you topology in cluster mode to have a try.
On the other hand, since there are many conflicting problems with log4j, we use slf4j as the default library for log4j like this
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyBolt {
private static final Logger LOG = LoggerFactory
.getLogger(MyBolt.class);
}
and excludes all other log4j libs in all dependencies like this
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.10</artifactId>
<version>0.8.2.1</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
Hope this helps.

Override logging in WildFly

I used tomcat and simply override default logging system. How to enable logging with logback on wildfly in my spring app?
My Logback.xml owrking on tomcat
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
</encoder>
</appender>
<logger name="org.springframework" level="WARN" />
<logger name="com.citronium.planstery" level="INFO" />
<logger name="org.apache.http.impl.conn.tsccm" level="ERROR" />
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
You can use logback to configure logging in your application. You can't use logback to configure logging for the server.
To use logback in your configuration you'll need to change the add-logging-api-dependencies to false or create a jboss-deployment-structure.xml that excludes the subsystem. You'll also need to include logback and slf4j in your deployment.
The first option of changing the add-logging-api-dependencies is a global setting for all deployments. The follow CLI command will change the value:
/subsystem=logging:write-attribute(name=add-logging-api-dependencies,value=false)
This option simply doesn't add any of the implicit logging dependencies to your deployment.
The second option of using a jboss-deployment-structure.xml will disable the logging subsystem for your deployment only. The following is an example file:
<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>
Here is how we do this, by the way, we are using wildfly-8.1.0-Final.
First, make a jar file containing this class:
https://gist.github.com/xiaodong-xie/219491e0b433f8bd451e
Then put this jar file into "wildfly-8.1.0.Final/modules/system/layers/base/org/jboss/logmanager/main", and add a reference to this jar file in the module.xml file in the exact same folder.
Then put "logback-classic-1.1.2.jar" and "logback-core-1.1.2.jar" (You can use any version of logback you choose) into "wildfly-8.1.0.Final/modules/system/layers/base/org/jboss/logmanager/main", and reference those 2 jar files in the module.xml file.
Add the following to the "subsystem:logging" in the standalone.xml you are using:
<custom-handler name="logback" class="org.slf4j.bridge.SLF4JBridgeHandler" module="org.jboss.logmanager"></custom-handler>
And reference this handler in the root-logger element following:
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="logback"/>
</handlers>
</root-logger>
Here is an example of logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
<appender name="LOGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${JBOSS_HOME}/standalone/log/server-logback.log</file>
<append>true</append>
</appender>
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="LOGFILE"/>
</appender>
<root level="INFO">
<appender-ref ref="ASYNC"/>
</root>
</configuration>
And put this logback.xml file into "wildfly-8.1.0.Final/standalone/configuration" folder.
Add the following to the "standalone.sh" or equivalent in the "wildfly-8.1.0.Final/bin" folder.
-Dlogback.configurationFile=file:$JBOSS_CONFIG_DIR/logback.xml
Just under "-Dlogging.configuration=file:$JBOSS_CONFIG_DIR/logging.properties" line. There are 2 places in "standalone.sh" file.
=================================================================================
Or you can do it in a simpler way. :)
Put the 2 logback jar files to the "jboss.logmanager" module, and add "-Dorg.jboss.logging.provider=slf4j" to the "standalone.sh" file, the same position.
I found there are some logging missing if going this by the way, since Wildfly itself still using its own logging facility if going this way.
Have fun. :-)