Wildfly 13 - Proper project setup using logback in an ear project - wildfly

I am deploying my application as an ear archive in wildfly 13. The ear contains a war and an ejb. The ejb is used in different projects. I want to log the information from the war and the ejb into a single file to have the full context what happend in a single logfile.
I managed to log from the war via logback, but the logs from the ejb are not logged via logback.
My current setup:
In my ear-module I have a jboss-deployment-structure.xml in my ear file to exclude the logging subsystem
In my web-module the logback.xml is located in WEB-INF/classes
In my web-module I have the dependencies to logback-classic and slf4j
In my ejb-module I have a dependency to slf4j
Any suggestions?

If you're just logging to a file you could use a logging-profile which would allow you to make runtime changes and not have to redploy your application if you want to make changes to your logging configuration.
Using WildFly Logging
Example Profile Configuration
/subsystem=logging/logging-profile=ear1:add
/subsystem=logging/logging-profile=ear1/pattern-formatter=PATTERN:add(pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n")
/subsystem=logging/logging-profile=ear1/periodic-rotating-file-handler=FILE:add(append=true, suffix=".yyyy-MM-dd", named-formatter=PATTERN, file={relative-to=jboss.server.log.dir, path="ear1.log"})
/subsystem=logging/logging-profile=ear1/root-logger=ROOT:add(level=INFO, handlers=[FILE])
Then you'd just add Logging-Profile: ear1 entry in your EAR's manifest.
Using Logback
If you want to continue using logback you'd need to put the logback and slf4j dependencies in your EAR/lib directory. The trick will be figuring out where to put the logback configuration file. It might work in EAR/META-INF or in the EAR/lib, but I'm not certain. It may even work if you kept it in the WAR/WEB-INF/classes, but you'd need to ensure a logger is accessed in the WAR before one is accessed in the EJB.
You'll also want to ensure you exclude the org.slf4j.api module or the logging subsystem for the EAR and each subdeloyment in your jboss-deployment-structure.xml.

Related

How to create separate log files for every jar that present in war file in JBOSS EAP/Wildfly

I have deployed one war file in JBOSS eap7.4, but all my logs are going to server.log file by default. I have 2 jars in my war file for which I need to log messages in separate files. Please help me.
This is the custom handler I have created in standalone.xml
And this is the module.xml
This is my log4j.xml file to implement logs for 2 jars with their package names
You need to exclude the org.apache.logging.api from your deployment in a jboss-deployment-structure.xml file. Then include both the log4j-api and log4j-core libraries in your deployment if you want to use a log4j2 configuration file. See the JBoss EAP 7.4 documentation for more details.
You need to achieve this using logging profiles. Please refer
https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/6.4/html/administration_and_configuration_guide/sect-logging_profiles

getRootLogger() equivalent in JBoss Logging

I am migrating an application from Weblogic to JBoss EAP 6.4. The application originally used Log4J and an external logging configuration properties file. From what I understand, using Log4J would require the log4j.xml or log4j.properties file to be packaged inside the EAR and it would prevent us from changing the logging configuration at runtime.
Currently, I am ok with using the JBoss Logging subsystem to do the logging. However, the application has calls like:
Logger rootLogger = Logger.getRootLogger();
What is the equivalent in JBoss Logging, if I needed to get the RootLogger?
You can use log4j essentially as a logging facade. In other words you don't need to change your logging code at all.
If you want to use the logging subsystem for configuration just ensure your deployment does not have a log4j.xml or log4j.properties file as you stated.
If you want to swap out log4j and use JBoss Logging the equivalent for Logger.getRootLogger() would just be Logger.getLogger("").

JBOSS7 external jar with dependency on ear file

I am using JBOSS 7
In my custom jar I am implementing an Interface. The interface is in a jar packaged with ECM.ear file. Unless I put my custom jar inside the web-inf/lib folder (of the war file located in ear file) I am getting ClassNotFoundException w.r.to the interface.
I created a module for my custom jar but I don't how to set up a dependency with ear file. I copied the jar containing the interface say mdm.jar and placed it in the module and also added an entry in the resource root of module.xml. After restarting I am getting ClassNotFoundException for the classes referred by mdm.jar, which arein ear file.
How to achieve this dependency?
Thanks,
Raghu
JBOSS 7 needs you to place the packaged jar files in the lib folders of your web-inf/lib or the ear/lib cos of the Class Loading Precedence that JBOSS server follows.
Alternatively you could load it as a module, but you need to specify any addition of this kind outside of JBOSS default supplied modules using your MANIFEST file or jboss-deployment-structure.xml
This link should provide you more insight on what would suit you best.
Hope it helps.

How to change logging level with Mule studio Eclipse plugin

Mule studio loads the log4j properties file from ...eclipse\plugins\org.mule.tooling.server.3.3.1_1.3.2.201212121943\mule\tooling\tooling-support-3.3.1.jar instead of the one provided in the project root folder.
The log4j.properties should be located in src/main/resources, and not in the root folder. You can use the log4j.properties file from the jar as a template and change the logging level with log4j.rootCategory=DESIREDLEVEL, console:
# Default log level
log4j.rootCategory=INFO, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%-5p %d [%t] %c: %m%n
################################################
# You can set custom log levels per-package here
################################################
# Apache Commons tend to make a lot of noise which can clutter the log.
log4j.logger.org.apache=WARN
# Shuts up some innocuous messages if using the JBPM transport
log4j.logger.org.hibernate.engine.StatefulPersistenceContext.ProxyWarnLog=ERROR
# Reduce startup noise
log4j.logger.org.springframework.beans.factory=WARN
# Mule classes
log4j.logger.org.mule=INFO
# Your custom classes
log4j.logger.com.mycompany=DEBUG
I found an article that helped me resolve this problem in Mule ESB 3.6. This Mulesoft version uses log4j2 and looks for config as below:
When an application is deployed, Mule will look for a config following
a child first pattern like this:
Look for a file called log4j2-test.xml in the application classpath
Look for a file called log4j2.xml in the application classpath
Look for a file called log4j2-test.xml in the domain classpath
Look for a file called log4j2.xml in the domain classpath
Look for a file called log4j2-test.xml in MULE_HOME/conf
Look for a file called log4j2.xml in MULE_HOME/conf
Apply default configuration.
Just put logj2.xml on classpath ie in src/main/resources. It works.
Link to the article:
http://blogs.mulesoft.org/mule-3-6-asynchronous-logging/

deploy.last in JBoss 5.1 in web configuration?

We have ear that depends on war file.
We use web configuration.
I put war file to <jboss_home>/server/web/deploy directory.
And I put ear file to <jboss_home>/server/web/deploy/deploy.last directory.
But ear starts prior to war.
Why?
I use a similar configuration to what you describe, though I put all the apps I want to deploy first in deploy/myapps and all the ones to deploy afterwards in deploy/myapps.last. This works correctly for me on JBoss 5.1.2.
Although I can't explain why it isn't working for you, I can offer an alternative solution. You can make the EAR declare a dependency on the WAR and JBoss will then ensure the WAR is deployed first.
First, add a file called aliases.txt into the META-INF directory of your WAR. This file should just contain a single line with an arbitrary name / identifier for your WAR. For example, if you have mywebapp.war, your META-INF/aliases.txt file could contain 'mywebapp'. It just needs to be something that won't clash with any other aliases declared by other apps deployed on the same server.
Next, add a jboss-dependency.xml file to the META-INF directory of your EAR, containing the following (subsituting 'mywebapp' for the alias you created above):
<dependency xmlns="urn:jboss:dependency:1.0">
<item whenRequired="Real" dependentState="Create">mywebapp</item>
</dependency>
This should ensure the WAR is deployed before the EAR.
Also, if you try to deploy the EAR without the WAR being present, JBoss will log a clear deployment error message telling you about the missing dependency.